Joomla 3 add multiple rows to database
Sample code to add multiple rows to Joomla 3 databse. For what ever reason i could find this anywhere
i have used a for loop, but you could use a foreach or what ever i guess. Be careful. I wrecked a databse using this code.
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Insert columns.
$columns = array('category_id', 'item_id');
//Loop through 100 times
for($i=1; $i<=100;$i++){
$values[] = "1, ".$i;
}
// Prepare the insert query.
$query
->insert($db->quoteName('#__zoo_category_item')) //dont foget to edit this value to suit your table
->columns($db->quoteName($columns))
->values($values);
// Set the query using our newly populated query object and execute it.
$db->setQuery($query);
$db->query();