samona Posted October 23, 2008 Share Posted October 23, 2008 is there a way to insert more than one record into the database without have to have a loop as I have below? for ($i = 1; $i <= 4; $i++) { $index = "info_{$i}"; $query = "Update table SET column = '{$_POST[$index]}' WHERE column_ID = $i"; if (!($result = @mysql_query($query, $connection))) { die ('Could not query the databases: ' . mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/ Share on other sites More sharing options...
trq Posted October 23, 2008 Share Posted October 23, 2008 Not via php no. mysql_query will only except one query at a time. Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/#findComment-673207 Share on other sites More sharing options...
fenway Posted October 23, 2008 Share Posted October 23, 2008 First, that's updating, not insert... you can definitely insert multiple at a time Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/#findComment-673245 Share on other sites More sharing options...
teng84 Posted October 23, 2008 Share Posted October 23, 2008 @thorpe i think what he means is that to have one huge query.. this is update statement with a where clause so i guess you cant do it all at one query unlike insert Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/#findComment-673251 Share on other sites More sharing options...
samona Posted October 23, 2008 Author Share Posted October 23, 2008 how can i insert multiple records with one query? Maybe this way i can just add records and request the latest one. Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/#findComment-673264 Share on other sites More sharing options...
trq Posted October 23, 2008 Share Posted October 23, 2008 You can't. mysql_query() won't let you. This is a php thing. You can execute mutiple queries seperated by colons in mysql directly, but not through php's mysql_query(). Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/#findComment-673287 Share on other sites More sharing options...
fenway Posted October 24, 2008 Share Posted October 24, 2008 But INSERT can have multiple VALUES() clauses.... Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/#findComment-673363 Share on other sites More sharing options...
trq Posted October 24, 2008 Share Posted October 24, 2008 Indeed, but I think the op is asking how to insert more than one record. Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/#findComment-673380 Share on other sites More sharing options...
fenway Posted October 24, 2008 Share Posted October 24, 2008 Indeed, but I think the op is asking how to insert more than one record. You mean into different tables, thn. Link to comment https://forums.phpfreaks.com/topic/129858-solved-multiple-records-with-one-sql-statement/#findComment-673776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.