Author Topic: Bulk update  (Read 305 times)

0 Members and 1 Guest are viewing this topic.

Offline rhodry_korbTopic starter

  • Enthusiast
  • Posts: 357
    • View Profile
Bulk update
« on: March 13, 2010, 11:06:38 PM »
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
Only ten percent of the code in any given program will ever execute
The sooner you start coding a program, the longer it will take

Offline rhodry_korbTopic starter

  • Enthusiast
  • Posts: 357
    • View Profile
Re: Bulk update
« Reply #1 on: March 13, 2010, 11:12:14 PM »
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
Quote
Fatal error: Maximum execution time of 30 seconds exceeded

So I need a faster way, or better way

Thanks

Only ten percent of the code in any given program will ever execute
The sooner you start coding a program, the longer it will take

Offline DavidAM

  • Devotee
  • Posts: 1,026
  • Gender: Male
    • View Profile
Re: Bulk update
« Reply #2 on: March 13, 2010, 11:41:57 PM »
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.
-- I haven't lost my mind, it's backed up on tape ... somewhere!

Offline rhodry_korbTopic starter

  • Enthusiast
  • Posts: 357
    • View Profile
Re: Bulk update
« Reply #3 on: March 13, 2010, 11:44:35 PM »
Thanks so much
Only ten percent of the code in any given program will ever execute
The sooner you start coding a program, the longer it will take