Jump to content

Select from DB Not Working?


dyr

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.

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.