-1

I have the following code which generates the following message. I have used mysql_num_rows() before without any issue and even though it is now giving me a warning it still shows the results. Any ideas would be appreciated.

$days_ago1 = date('Y-m-d', mktime(0, 0, 0, date("m") , date("d") - 1, date("Y")));
$result = mysql_query("SELECT * FROM daily_count WHERE date='$days_ago1' and  member ='$site_id'");
$num_rows1 = mysql_num_rows($result);

and this is the warning:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/track003/public_html/livetrack/data/graph_data.php on line 5

Line 5 is the last line of the code.

Jocelyn
  • 11,209
  • 10
  • 43
  • 60

2 Answers2

1

Does the query run when you paste it into a mysql client command line?

echo "SELECT * FROM daily_count WHERE date='$days_ago1' and  member ='$site_id'";

and put it in mysql and see does it return rows.

ncremins
  • 9,140
  • 2
  • 25
  • 24
  • In short no, but it displays the results now, it just also provides an error –  Mar 24 '12 at 12:33
  • Thanks but it already returns the results, so i can't see what putting it through mysql will show? –  Mar 24 '12 at 12:53
0

mysql_query returns FALSE when the query fails for whatever reason. You should always check the return value:

if ($result === FALSE) {
    die('DB ERROR: '.mysql_error());
}
Joni
  • 108,737
  • 14
  • 143
  • 193
  • ok, but it is showing a result? –  Mar 24 '12 at 12:53
  • any chance you are fetching the results from a different query? `mysql_num_rows` doesn't lie, if it says the resource is not valid it's not. – Joni Mar 24 '12 at 13:54
  • OK I SOLVED IT, I DON'T KNOW HOW BUT I COPIED AND PASTE THE INFO FROM ANOTHER PAGE ADJUSTED THAT AND IT WORKED..... THANKS FOR YOUR HELP –  Mar 24 '12 at 15:48