lostprophetpunk Posted December 24, 2008 Share Posted December 24, 2008 I am trying to use the function of mysql_num_rows() to count some rows in my database. However, I have hit a snag. It seems to be saying that one of the arguments is not valid for it. $result = mysql_query("SELECT FROM `pm` WHERE `username`='".$Data8['username']." && status`='unread'"); $num_roows = mysql_num_rows($result); It seems to return this error... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\member\header.php on line 141 What I am trying to do is to have it count the selected rows from the database where they equal two separate fields. So it is more like... select from table where username=username and status=unread... so how would I do this? Link to comment https://forums.phpfreaks.com/topic/138332-solved-mysql_num_rows-problem/ Share on other sites More sharing options...
genericnumber1 Posted December 24, 2008 Share Posted December 24, 2008 Change mysql_query("SELECT FROM `pm` WHERE `username`='".$Data8['username']." && status`='unread'"); to mysql_query("SELECT FROM `pm` WHERE `username`='".$Data8['username']." && status`='unread'") or die(mysql_error()); it should tell you what is wrong with your query (I can spot it!, can you?) Link to comment https://forums.phpfreaks.com/topic/138332-solved-mysql_num_rows-problem/#findComment-723307 Share on other sites More sharing options...
revraz Posted December 24, 2008 Share Posted December 24, 2008 If you echo the query you'll see you forgot a single quote in there for the username variable. Link to comment https://forums.phpfreaks.com/topic/138332-solved-mysql_num_rows-problem/#findComment-723316 Share on other sites More sharing options...
lostprophetpunk Posted December 24, 2008 Author Share Posted December 24, 2008 Change mysql_query("SELECT FROM `pm` WHERE `username`='".$Data8['username']." && status`='unread'"); to mysql_query("SELECT FROM `pm` WHERE `username`='".$Data8['username']." && status`='unread'") or die(mysql_error()); it should tell you what is wrong with your query (I can spot it!, can you?) I have done that now I get this error... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `pm` WHERE `username`='mini' && `status`='unread'' at line 1 Current code... $result = mysql_query("SELECT FROM `pm` WHERE `username`='".$Data8['username']."' && `status`='unread'")or die(mysql_error()); $num_roows = mysql_num_rows($result); Link to comment https://forums.phpfreaks.com/topic/138332-solved-mysql_num_rows-problem/#findComment-723323 Share on other sites More sharing options...
MadTechie Posted December 24, 2008 Share Posted December 24, 2008 $result = mysql_query("SELECT * FROM `pm` WHERE `username`= '".$Data8['username']."' AND `status`='unread' ") or die(mysql_error()); $num_roows = mysql_num_rows($result); you missed the field selection Link to comment https://forums.phpfreaks.com/topic/138332-solved-mysql_num_rows-problem/#findComment-723326 Share on other sites More sharing options...
lostprophetpunk Posted December 24, 2008 Author Share Posted December 24, 2008 $result = mysql_query("SELECT * FROM `pm` WHERE `username`= '".$Data8['username']."' AND `status`='unread' ") or die(mysql_error()); $num_roows = mysql_num_rows($result); you missed the field selection Yeah I realised that just after I posted...my head is so screwed at the moment. Link to comment https://forums.phpfreaks.com/topic/138332-solved-mysql_num_rows-problem/#findComment-723328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.