Page 1 of 1

Warning: mysql_fetch_assoc(): showing in PHP 5.2 but not 4

Posted: Mon Jan 21, 2013 5:57 am
by jonnyfortis
hello
I am building a shopping cart site that was on 1&1 and it was using PHP4 but now i have moved the cart integration and needed to move it up and am now running php 5.2 but an error has now come up within the content of and image that is has a Tom Muck repeat region in it

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in/homepages/6/d132436789/htdocs/beta/product-list.php on line 169


<?php
$None_endRow = 0;
}
} while ($row_None = mysql_fetch_assoc($None));
if($None_endRow != 0) {
while ($None_endRow < $None_columns) {
echo("<td> </td>");
$None_endRow++;
}
echo("</tr>");
}?>

the error line being
if($None_endRow != 0) {

the page still functions but how do i clear this error?


thanks in advance

Re: Warning: mysql_fetch_assoc(): showing in PHP 5.2 but not

Posted: Mon Jan 21, 2013 6:35 am
by twinedev
It doesn't sound like a difference in the versions of PHP, but more of the settings for PHP. On old server it was most likely set to hide warnings by default, and the new server shows them (which, IMO it is best to have them on and report everything when you are developing the script, otherwise like in your case, things don't pop up till you get to a different environment)

Provide proper checking that the query actually returned data before trying to use it:

Code: Select all

$None = mysql_query($SQL_Statement);
if ($None && mysql_num_rows($None)>0) {

  // Your code to use data
	
  mysql_free_result($None);
}
else {
  // Optional Code to display when there are no results
} 

Re: Warning: mysql_fetch_assoc(): showing in PHP 5.2 but not

Posted: Mon Jan 21, 2013 7:24 am
by jonnyfortis
ok. for now i have just added

error_reporting(0);

this isnt good because thats not the point but the site is live

i will try your advise in my testing area

Re: Warning: mysql_fetch_assoc(): showing in PHP 5.2 but not

Posted: Mon Jan 21, 2013 8:21 am
by jonnyfortis
the problem was i hadnt defind the recordset in the query

Code: Select all

            <?php
 $rsProductData_endRow = 0;
  }
} while ($row_rsProductData = mysql_fetch_assoc($rsProductData));
if($rsProductData_endRow != 0) {
while ($rsProductData_endRow < $rsProductData_columns) {
    echo("<td>&nbsp;</td>");
    $rsProductData_endRow++;
}
echo("</tr>");
}?>