Jump to content

Mysql Update Problem


ProblemHelpPlease

Recommended Posts

I have the following code layout but the UPDATES do not work and the script returns no errors.

$result = mysql_query("SELECT * FROM blah WHERE blah = 'blah'");while($row = mysql_fetch_array($result)){mysql_query("UPDATE blah SET blah = 'blah' WHERE blah = '$row['blah']'");}

Can I use an UPDATE in the middle of the while like this?

Link to comment
Share on other sites

I had actually been using

$result = mysql_query("SELECT * FROM blah WHERE blah = 'blah'");while($row = mysql_fetch_array($result)){$blah = $row['blah'];mysql_query("UPDATE blah SET blah = 'blah' WHERE blah = '$blah'");}

But both the above and your suggestion have no effect. I was really looking to check if using a mysql_query UPDATE inside a while mysql_fetch_array was ok or if this was the cause of it not working.I dont understand why I am not seeing any error messages, if i pull the UPDATE out and run it on its own then it works so I know that the UPDATE itself is ok.

Link to comment
Share on other sites

It doesn't matter which control structures you put calls to MySQL in, MySQL doesn't check to see what the structure of the PHP code was where the call was made. If it's not running the update queries, then it's probably not looping at all, which means the select statement isn't returning any rows.It's not going to automatically print errors from MySQL, if you want to see those you need to check if an error happened (mysql_query will return false if there was an error), and use the mysql_error function to print the error message.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...