MasterACE14 Posted April 23, 2008 Share Posted April 23, 2008 morning, I have a basic check for how many rows there are in a query and its throwing me this error. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ace/public_html/conflictingforces/lib/messages.php on line 28 here's my code(relevant code only): <?php // the query $query = mysql_query("SELECT * FROM `cf_messages` WHERE owner='$player[id]' ORDER BY date DESC LIMIT 50"); // line 28 , the rows if (mysql_num_rows($query) == 0) ?> any help is greatly appreciated. Regards ACE Link to comment https://forums.phpfreaks.com/topic/102621-warning-mysql_num_rows/ Share on other sites More sharing options...
DarkWater Posted April 23, 2008 Share Posted April 23, 2008 $query = mysql_query("SELECT * FROM cf_messages WHERE owner='{$player['id']}' ORDER BY date DESC LIMIT 50"); // line 28 , the rows if (mysql_num_rows($query) == 0) You need to use {} around arrays when echoing them or using them in double quotes. And DON'T USE ` FOR COLUMN NAMES. Thanks. =) Link to comment https://forums.phpfreaks.com/topic/102621-warning-mysql_num_rows/#findComment-525547 Share on other sites More sharing options...
Barand Posted April 23, 2008 Share Posted April 23, 2008 Debugging hint #1 Put the query into a $var before calling mysql_query() $sql = "SELECT * FROM `cf_messages` WHERE owner='$player[id]' ORDER BY date DESC LIMIT 50"; Debugging hint #2 get the content of mysql_error() to tell you why it failed $res = mysql_query ($sql) or die (mysql_error() , ' in ' . $sql); Link to comment https://forums.phpfreaks.com/topic/102621-warning-mysql_num_rows/#findComment-525555 Share on other sites More sharing options...
MasterACE14 Posted April 23, 2008 Author Share Posted April 23, 2008 that has fixed it. thanks guys by the way, do you have MSN DarkWater? quite a coincidence were both 15 and have been coding in PHP for a few years add me if you do. ace @ crikeygames . com . au Link to comment https://forums.phpfreaks.com/topic/102621-warning-mysql_num_rows/#findComment-525564 Share on other sites More sharing options...
trq Posted April 23, 2008 Share Posted April 23, 2008 You should always check that mysql_query() returned a result resource (this is not the same as returning rows) prior to trying to use it. eg; <?php $sql = "SELECT foo FROM bar"; if ($result = mysql_query($sql)) { // query worked, check for rows. if (mysql_num_rows($result)) { // rows found, display data. } else { // no rows found. } } else { // query failed, handle error. } ?> Link to comment https://forums.phpfreaks.com/topic/102621-warning-mysql_num_rows/#findComment-525577 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 I added you to MSN. =P Link to comment https://forums.phpfreaks.com/topic/102621-warning-mysql_num_rows/#findComment-525613 Share on other sites More sharing options...
MasterACE14 Posted April 24, 2008 Author Share Posted April 24, 2008 You should always check that mysql_query() returned a result resource (this is not the same as returning rows) prior to trying to use it. eg; <?php $sql = "SELECT foo FROM bar"; if ($result = mysql_query($sql)) { // query worked, check for rows. if (mysql_num_rows($result)) { // rows found, display data. } else { // no rows found. } } else { // query failed, handle error. } ?> ok, I will do that from now on, thanks I added you to MSN. =P excellant Link to comment https://forums.phpfreaks.com/topic/102621-warning-mysql_num_rows/#findComment-525642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.