Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.