Title: $wpdb-&gt;insert &#8211; inserting multiple rows
Last modified: August 20, 2016

---

# $wpdb->insert – inserting multiple rows

 *  [albinjoseph](https://wordpress.org/support/users/albinjoseph/)
 * (@albinjoseph)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/wpdb-insert-inserting-multiple-rows/)
 * How do I use $wpdb->insert to insert multiple rows. Here is my code.
 *     ```
       for($i=0; $i<=$urlCount; $i++) {
       	$stat = $wpdb->insert(
       		'WP_URLS',
       		array(
       			'POSTID' => $post->ID,
       			'URL' =>   $_POST['url'.$i]
       		)
       	);
       }
       ```
   
 * This code works only for the first insert (ie, when $i = 1). Sometimes the URL
   count will be more than 100 and sometimes it will be zero. So instead of writing
   the code for 100 times, I just want to have a simple loop that works for any 
   number of records. Thats the reason I went for loop.
 * Thank you for the help.

The topic ‘$wpdb->insert – inserting multiple rows’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [albinjoseph](https://wordpress.org/support/users/albinjoseph/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/wpdb-insert-inserting-multiple-rows/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
