techiefreak05 Posted August 21, 2006 Share Posted August 21, 2006 I'm creating a message system on my site, which works fine, but theres one thing, letting a user know they have new messages! I think i'd use this somewhere...[code]SELECT * FROM `messages` WHERE `to` = '$to' AND `status` = 'no'[/code]the variable "$to" will be defined, it will be $to = '$_SESSION[username]'I want to echo "New Messages" if anywhere in the "status" column equals "no" , how would I do this? Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/ Share on other sites More sharing options...
desithugg Posted August 21, 2006 Share Posted August 21, 2006 [code]$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");if (!$result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result);$new = $row[0];if($new == ""){$new = "0";}if(new != "0" ){echo "You have $new new messages.";}[/code]umm try this Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78310 Share on other sites More sharing options...
Jeremysr Posted August 21, 2006 Share Posted August 21, 2006 Use [url=http://ca3.php.net/manual/en/function.msql-num-rows.php]mysql_num_rows[/url]() to find out how many new messages they have. If they have more than 0 new messages, display the New Messages link. Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78311 Share on other sites More sharing options...
techiefreak05 Posted August 21, 2006 Author Share Posted August 21, 2006 I used this[code]$to = '$_SESSION[username]'$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");if (!$result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result);$new = $row[0];if($new == ""){$new = "0";}if(new != "0" ){echo "<font color=red><b>You have $new new messages!</b></font>";}[/code]and got this error:[code]Parse error: syntax error, unexpected T_VARIABLE in /home/zyco/public_html/newlayout/main.php on line 32[/code] Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78312 Share on other sites More sharing options...
Jeremysr Posted August 21, 2006 Share Posted August 21, 2006 You're missing a semi-colon on the first line in your code that you showed above. Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78314 Share on other sites More sharing options...
techiefreak05 Posted August 21, 2006 Author Share Posted August 21, 2006 I aded the semicolon onto [code]$to = '$_SESSION[username]'[/code] and now i get this error:[code]Parse error: syntax error, unexpected T_IS_NOT_EQUAL, expecting T_STRING or T_VARIABLE or '$' in /home/zyco/public_html/newlayout/main.php on line 43[/code] Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78316 Share on other sites More sharing options...
Jeremysr Posted August 21, 2006 Share Posted August 21, 2006 Well which line is line 43? BTW you don't put quotes when your assigning a variable to another variable like that.$to = $_SESSION[username]; Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78321 Share on other sites More sharing options...
techiefreak05 Posted August 22, 2006 Author Share Posted August 22, 2006 here is LINES 27 - 47(the whole PHP script)[code] <?phpif($logged_in){headerLinks();$to = '$_SESSION[username]';$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");if (!$result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result);$new = $row[0];if($new == ""){$new = "0";}if(new != "0" )(43){echo "<font color=red><b>You have $new new messages!</b></font>";}}?>[/code] Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78382 Share on other sites More sharing options...
desithugg Posted August 22, 2006 Share Posted August 22, 2006 remove the $to = '$_SESSION[username]';quotesmake it $to = $_SESSION['username']; thats where i think the error is thats all i can see o my bad i see ur and ur missingo sorry i mis read it instead of doingif($logged_in){and than } at the end tryif(!$logged_in){echo"please login";exit;} Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78386 Share on other sites More sharing options...
techiefreak05 Posted August 22, 2006 Author Share Posted August 22, 2006 I still get the same error:[code]Parse error: syntax error, unexpected T_IS_NOT_EQUAL, expecting T_STRING or T_VARIABLE or '$' in /home/zyco/public_html/newlayout/main.php on line 41[/code]with this as my updated code:[code] <?phpif($logged_in){headerLinks();$to = $_SESSION[username];$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");if (!$result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result);$new = $row[0];if($new = ""){$new = "0";}if(new != "0" ){echo "<font color=red><b>You have $new new messages!</b></font>";}}?>[/code]LINE 41 IS:[code]if(new != "0" ){[/code] Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78390 Share on other sites More sharing options...
desithugg Posted August 22, 2006 Share Posted August 22, 2006 i dont see any error on that line try updating the code to this[code] <?phpif(!$logged_in){echo"Please Log-in";exit;}headerLinks();$to = $_SESSION['username'];$result = mysql_query("SELECT count(*) FROM `messages` WHERE `to` = '$to' AND `status` = 'no'");if (!$result) { echo 'Could not run query: ' . mysql_error(); exit;}$row = mysql_fetch_row($result);$new = $row[0];if($new = ""){$new = "0";}if(new != "0"){echo "<font color='red'><b>You have $new new messages!</b></font>";}?>[/code]im pretty sure this will work Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78391 Share on other sites More sharing options...
techiefreak05 Posted August 22, 2006 Author Share Posted August 22, 2006 ok, i got the problem fixed.. wanna hear the solution, your gonna beat yourself... look, whats wrong with this:[code]if(new != "0"){[/code]it SHOULD be [code]if($new != "0"){[/code]haha now go kick yourself :P lmao! Link to comment https://forums.phpfreaks.com/topic/18240-idk-how-to/#findComment-78399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.