Jump to content

multi insert


flemingmike

Recommended Posts

hello,  is there a way to insert something 17 times into a database and change the 3rd field one at a time (from 1-17)?

 

$sql = "INSERT INTO picks VALUES (
 NULL, 
 '" . mysql_real_escape_string($userid) ."',
 '" . mysql_real_escape_string($weekid) ."',
 '" . mysql_real_escape_string($pickid) ."'
 )";
	mysql_query($sql) or die('Error, Check you fields and try again.');

Link to comment
https://forums.phpfreaks.com/topic/246587-multi-insert/
Share on other sites

If I understand what you're asking (and I think I do), it can be done rather easily. Why are you escaping what appear to most likely be numeric values though?

 

$userid = (int) $userid = 55;
$pickid = (int) $pickid = 66;

$values = array();

for( $weekid = 1; $weekid < 18; $weekid++ ) {
$values[] =  "( '', $userid, $weekid, $pickid )";
}

$query = " INSERT INTO picks VALUES " . implode( ', ', $values );

Link to comment
https://forums.phpfreaks.com/topic/246587-multi-insert/#findComment-1266292
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.