canadabeeau Posted March 14, 2010 Share Posted March 14, 2010 Hi I am developing a bulk update script, which is below function db_update($table){ $mysqli = db_connect(); $query = "UPDATE $table SET "; foreach($_POST as $aKey=>$aValue){ while($aValue){ $query = $query . " `value` = '$aValue' WHERE `tag`='$aKey'"; $mysqli->query($query) or die("My SQL didn't work in update query." . mysql_error() . $query. '<br><hr>'); } } } It works by retrieving the name of each POST (eg 'date') and then inserts it into the coulmn 'value' where tag = date now the problem is the above is not working properly, it is not making one query per $_POST and I need it to do that for it to work as you cant have multiple WHERE clauses for the one query Any help is greatly appreciated Link to comment https://forums.phpfreaks.com/topic/195165-bulk-update/ Share on other sites More sharing options...
canadabeeau Posted March 14, 2010 Author Share Posted March 14, 2010 okay guys I now have this function db_update($table){ $mysqli = db_connect(); foreach($_POST as $aKey=>$aValue){ while($_POST){ $query = "UPDATE $table SET "; $query = $query . " `value` = '$aValue' WHERE `tag`='$aKey'"; $mysqli->query($query) or die("My SQL didn't work in update query." . mysql_error() . $query. '<br><hr>'); } } } which sort of works but results in Fatal error: Maximum execution time of 30 seconds exceeded So I need a faster way, or better way Thanks Link to comment https://forums.phpfreaks.com/topic/195165-bulk-update/#findComment-1025804 Share on other sites More sharing options...
DavidAM Posted March 14, 2010 Share Posted March 14, 2010 I don't know why you have the while($_POST) inside that loop. It will always evaluate to true, so you are doing the update for the first POST key over and over again; that's why you got the execution time error. Remove this while loop, and I think it is doing what you want. Link to comment https://forums.phpfreaks.com/topic/195165-bulk-update/#findComment-1025809 Share on other sites More sharing options...
canadabeeau Posted March 14, 2010 Author Share Posted March 14, 2010 Thanks so much Link to comment https://forums.phpfreaks.com/topic/195165-bulk-update/#findComment-1025810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.