-1

I know this question is asked daily, but my resource is not false.

$query = "SELECT ccnumber,CUID FROM response WHERE CUID <" . $_POST['CUID'] . " ORDER By CUID DESC LIMIT 1";
$result_prev = mysql_query( $query );

if( $result_prev === false )
{
    print 'failed: '.$result_prev;
}

if( mysql_num_rows( $result_prev ) > 0 )
{

When this code is run in the website it does not print out "failed:" and when I print the $result_prev it shows Resource id #25.

BUT I still seem to be having issues. The error log has:

PHP Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in

When I go into myPHP and run the same query I get a result.

I am kinda stuck as to how to figure this out. This is happens three times on the same page. Any help or suggestions would be appreciated.

brechmos
  • 1,246
  • 1
  • 11
  • 20
  • 1
    You're echoing "failed" but your code still exits that if test and moves on to the line of code that does the mysql_num_rows() – Mark Baker Feb 26 '13 at 19:24
  • 1
    You haven't shown the code where you call `mysql_fetch_assoc()`. Also you shouldn't be using the `mysql_*` functions as these are deprecated. Perhaps use `mysqli` or `PDO`. – Mike Brant Feb 26 '13 at 19:25
  • What does the mysql_num_rows function return? `var_dump()`'ing the variable may help. – mustafa.0x Feb 26 '13 at 19:26
  • I did the var_dump on the mysql_num_rows and I got int(1). So it appears to work. Problem is the webpage is taking 10s of seconds to run. I thought these errors would point at the issue. – brechmos Feb 26 '13 at 19:46

1 Answers1

0

Write like this

$query = "SELECT ccnumber,CUID FROM response WHERE CUID <" . $_POST['CUID'] . " ORDER By CUID DESC LIMIT 1";
$result_prev = mysql_query( $query ) or die( 'Error is: ' . mysql_error() );

if( mysql_num_rows( $result_prev ) > 0 )
{
    while($row = mysql_fetch_assoc($result_prev))
    {
        echo 'ccnumber:' . $row['ccnumber'] . '<br>';
        echo 'CUID:' . $row['CUID'] . '<br><br>';
        echo '------------------------<br>';
    }
}
Winston
  • 1,730
  • 2
  • 17
  • 29