Jump to content

[SOLVED] mysql_num_rows() problem


lostprophetpunk

Recommended Posts

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

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?)

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);

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.