Jump to content

for loop and sql queries


Tandem

Recommended Posts

I'm trying to use a for loop to insert records into my database. Here's some theoretical code:

[code]for ($i = 0 ; $i < $num ; $i++) {
$id = mysql_insert_id();
$do_insert = mysql_query("INSERT INTO BLAH (ID) VALUES('$id')");
}[/code]

when i do this, only 1 record is inserted, no matter what the value of $num ($num is always a posive number above 0 btw).

What should i do to make it insert the right numbr of records?

If you don't understand me or need more info just say.

Any help appreciated.
Link to comment
https://forums.phpfreaks.com/topic/18959-for-loop-and-sql-queries/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.