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
https://forums.phpfreaks.com/topic/161007-solved-quick-question/
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);

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

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

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.";
?>

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.