Jump to content

Recommended Posts

!= means NOT EQUAL TO.  Which means that if recieved equals anything other than 0, it will return true.  With recieved = 1, it would only return true if there was 1 message.

 

I hope I didn't confuse you are all.     

And here I thought that recieved was a true/false statement, not a numerical representation of the quantity of messages they had.

You could actually write is like this as well:

 

<?php

session_start();

include '../settings.php';

$user= get_username($_SESSION['user_id']);

$query = "SELECT * FROM messages WHERE reciever = '$user';

$result = mysql_query($query);

$f = mysql_fetch_array($result);

echo "you have ".$f[recieved]." message(s)";

?>

ok i found a slight error in my ways lol

the thing is.. if a message is not read its 0  if its read its 1 so i need to gather all the 0's not the 1ns so what would i do here :S

 

<? $user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved != 0";
$result = mysql_query($query);
$no_of_msgs = mysql_num_rows($result);
if ($no_of_msgs != 0){
  $data = mysql_fetch_assoc($result);
  echo "Inbox($no_of_msgs)";
}
else{
   print "Inbox";
}?>

lol nope back to square 1 again sorry lol

 

<? $user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved = 0";
$result = mysql_query($query);
$no_of_msgs = mysql_num_rows($result);
if ($no_of_msgs != 0){
  $data = mysql_fetch_assoc($result);
  echo "Inbox($no_of_msgs)";
}
else{
   print "Inbox";
}?>

 

 

<?php
$user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved = 0";
$result = mysql_query($query);
$no_of_msgs = mysql_num_rows($result);
if ($no_of_msgs != 0){
  $data = mysql_fetch_assoc($result);
  echo "Inbox($no_of_msgs)";
}
else{
   print "Inbox";
}?>

That should work

Let me make sure I understand your DB:

----------------------------------------

| ID | message | reciever | recieved      |

----------------------------------------

|int | varchar  | varchar | tinyint        |

----------------------------------------

|5  |    500    | 50        | 1                |

----------------------------------------

 

Something like that? And when a new message arrives, the field named 'recieved' is set to "0", right?

a down-and-dirty test:

<?php
$user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved = 0";
$result = mysql_query($query);
print "you have ".mysql_num_rows($result)." messages";
?>

if it says "0", then change your script to this:

<?php
$user= get_username($_SESSION['user_id']);$query = "SELECT * FROM messages WHERE reciever = '$user' AND recieved = '0';";
$result = mysql_query($query);
$no_of_msgs = mysql_num_rows($result);
if ($no_of_msgs != 0){
  $data = mysql_fetch_assoc($result);
  echo "Inbox($no_of_msgs)";
}
else{
   print "Inbox";
}?>

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.