Jump to content

[SOLVED] quick question


justAnoob

Recommended Posts

I have a table in mysql with a colum called 'status'.....The only thing that can go in the column is the word 'NEW', which is placed there when a member gets a new message. I am using the following code to get the number of new messages that a user has but it is not working. I tried using a var_dump to see what is going on and all i get is this...  string(6) "timcin" int(0) ... Any ideas why it is not giving me the number of rows that I have. Is is something to do with the way that I have the word 'NEW' in the databae?

<?php
include "connection.php";
$userid = $_SESSION['id'];
$sql=mysql_query('SELECT * FROM member_messages WHERE status = "NEW" and user_id = "$userid"');
$num_rows = mysql_num_rows($sql);
var_dump($userid, $num_rows);
echo "You have " . $num_rows . " new message(s).";
mysql_close();
?>

Link to comment
Share on other sites

It's a good idea to put your query in a variable, print the variable and then run your query.  That way you can see exactly what it is you are running.

 

$query='SELECT * FROM member_messages WHERE status = "NEW" and user_id ="' . $userid . '"';
print "About to run $query\n";
$sql = mysql_query($query);

Link to comment
Share on other sites

and also check if your sql command is running correctly and if not show the error with the "or die(mysql.error())" after the query...

 

$query='SELECT * FROM member_messages WHERE status = "NEW" and user_id ="' . $userid . '"';
print "About to run $query\n";
$sql = mysql_query($query) or die(mysql.error());

Link to comment
Share on other sites

Yes,,, NEW is capitalized in the database..... No one can figure this out... What is going on??

<?php
include "connection.php";
$userid = $_SESSION['id'];
$flip='SELECT id FROM member_messages WHERE status = "NEW" and user_id ="' . $userid . '"';
$flop = mysql_num_rows($flip);     // this line
if($flop >= 1)
{
   echo "You have new messages.";
}
?>

 

Tried using 'id' instead of '*' but still get the same error

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on commented line

Link to comment
Share on other sites

Hey I got it... Awesome,,, this was killing me...  This works... I'm so happy.

<?php
include "connection.php";
$fluke = $_SESSION['id'];
$flip = ("SELECT id FROM member_messages WHERE status = 'NEW' and sendto = '" . $fluke . "'"); 
$flop = mysql_query($flip); 
$freak = mysql_num_rows($flop);
if(!$freak) echo "";
else echo "You have new messages.";
?>

Link to comment
Share on other sites

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.