Jump to content

Recommended Posts

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

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.