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.
->insert($db->quoteName('#__zoo_category_item')) //dont foget to edit this value to suit your table 

// Set the query using our newly populated query object and execute it.

You may be interested in...

Had enough browsing?

Get in touch

Get in touch

We wont charge you for the inital project meeting. So really you have nothing to lose.

Fill out the form below with as much information as you can provide and we will be in touch with you asap to discuss.

Please type your full name. Also only allowing alpha numeric characters here. Why do you have all this fancy stuff in your name anyway?

Invalid email address.

Please enter a valid phone number.

Enquiry Type(*)
Invalid Input

Please only use alphanumeric characters in your message

Invalid Input