Click to See Complete Forum and Search --> : Need to insert same record multiple times


Evangogh
12-30-2006, 10:07 AM
Hello, all.

I would like to insert the same record into a MySql table 100 times, and was wondering how I could do that. I know it must be possible with a loop, but I don't know how to construct it, as I am just learning MySql.

Thanks in advance for any tips!

itbeings
12-30-2006, 07:55 PM
What script do you want to use in inserting this records? PHP?

Evangogh
01-02-2007, 10:18 AM
Sorry about that - yes, I am using PHP.

Thanks!

chazzy
01-02-2007, 10:35 AM
the easiest way is to build a multiple insert query.


$sql = "INSERT INTO table(column_list) VALUES";
$max = 100;
for($i=1;$i<=100;i++){
$sql .= "(values)";
if($i != $max)
$sql .= ","
}
echo $sql;

http://dev.mysql.com/doc/refman/5.0/en/insert.html

Evangogh
01-02-2007, 06:39 PM
Just what I needed - thanks!