Jump to content

Recommended Posts

$inbox = mysql_query("SELECT `status` FROM `inbox` WHERE to_mid = '".$_SESSION['id']."'");
$inbox = mysql_fetch_assoc($inbox);
	{
		if($inbox['status'] == 0){
echo 'NEW<br />'; }

else{ echo 'Old<br />'; }}

 

I'm trying to update my sidebar to tell users when they have new, unread messages or not.  New, unread messages are classified in the inbox table as a status of 0.  How come this code isn't working?  On the actual page the config.php page which connects to the DB is included.

Link to comment
https://forums.phpfreaks.com/topic/263294-select-from-db-not-working/
Share on other sites

If you are trying to find if there are any new/unread messages, your query would need to be -

 

$query = "SELECT COUNT(*) as num_new FROM inbox WHERE status = 0 AND to_mid = {$_SESSION['id']}";

 

You would then execute that $query statement, fetch the row from the result set, and access the $row['num_new'] value to get the count of the number of new/unread messages for the current user id.

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.