jimbojames5645
Programmer
I need to insert a bunch of data into a mysql table from an array, but I don't want to use a bunch of queries. Is there any way to insert data from an array directly into mysql besides a loop?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
$the_array = array ('foo', 'bar', 'baz);
$query = "INSERT INTO foo values ";
$first_element = TRUE;
foreach ($the_array as $value)
{
if (!$first_element)
{
$query .= ", ";
}
$query .= "('" . $value . "')";
$first_element = FALSE;
}