I’m trying to debug some code from previous developer (ie I wouldn’t normally program like this) and I’ve got an error I just can’t get rid of. The code below results in the output beneath it.
What I can’t figure out is how execution gets to the point of error, because the query result has already been checked (and output). Basically I’m confused and am losing the plot. Can anyone help?
$res = mysql_query($query);
if(!$res) continue; //skip out of this loop iteration
$rows = mysql_num_rows($res);
if ($rows>0)
{
echo "Res : ";
var_dump($res);
while ($row = mysql_fetch_array($res)) //this is line 125
{
......
Res : resource(22) of type (mysql result)
PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in <snip />/getDetails.php on line 125
Well yeah, that seems to have done the trick. In that it’s not giving an error because it doesn’t try to execute the mysql_fetch_array. Even though it probably should.
I think Tom is probably right in that variables are being overwritten by previous iterations and other looping structures.
I think this code is too far gone to be able to live. I was hoping to understand and fix this bug but I think I’m going to rip it all out and start again.
If the result of the MySQL query fails, why would you want to continue and try to extract results? (From a query result that doesn’t exist). Or am I reading things wrong?
I’m assuming that hessodreamy had posted a snippet and simply implied the loops existence. It clearly isn’t the full set of code. Though, correct me if I’m wrong, @hessodreamy !