flemingmike Posted September 7, 2011 Share Posted September 7, 2011 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.'); Quote Link to comment https://forums.phpfreaks.com/topic/246587-multi-insert/ Share on other sites More sharing options...
Pikachu2000 Posted September 7, 2011 Share Posted September 7, 2011 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 ); Quote Link to comment https://forums.phpfreaks.com/topic/246587-multi-insert/#findComment-1266292 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.