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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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] Quote Link to comment 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. Quote Link to comment 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] Quote Link to comment 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]; Quote Link to comment 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] Quote Link to comment 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;} Quote Link to comment 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] Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.