dyr Posted May 28, 2012 Share Posted May 28, 2012 $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 More sharing options...
DanWhite Posted May 28, 2012 Share Posted May 28, 2012 mysql_fetch_array instead of assoc maybe? if not, run an "or die(mysql_error))" at the end of the query. Link to comment https://forums.phpfreaks.com/topic/263294-select-from-db-not-working/#findComment-1349360 Share on other sites More sharing options...
Barand Posted May 28, 2012 Share Posted May 28, 2012 Are you sure $_SESSION['id'] has the value you expect? Link to comment https://forums.phpfreaks.com/topic/263294-select-from-db-not-working/#findComment-1349361 Share on other sites More sharing options...
dyr Posted May 28, 2012 Author Share Posted May 28, 2012 $_SESSION['id'] contains the user's ID# in their session, which is the same number as to_mid. Tried array, to no avail. :/ Link to comment https://forums.phpfreaks.com/topic/263294-select-from-db-not-working/#findComment-1349365 Share on other sites More sharing options...
PFMaBiSmAd Posted May 28, 2012 Share Posted May 28, 2012 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. Link to comment https://forums.phpfreaks.com/topic/263294-select-from-db-not-working/#findComment-1349367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.