Jump to content

Archived

This topic is now archived and is closed to further replies.

techiefreak05

IDK how to ....

Recommended Posts

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?

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
You're missing a semi-colon on the first line in your code that you showed above.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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];

Share this post


Link to post
Share on other sites
here is LINES 27 - 47(the whole PHP script)

[code]  <?php
if($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]

Share this post


Link to post
Share on other sites
remove the
$to = '$_SESSION[username]';
quotes
make it
$to = $_SESSION['username']; thats where i think the error is thats all i can see o my bad i see ur
and ur missing

o sorry i mis read it instead of doing
if($logged_in){
and than } at the end
try
if(!$logged_in){
echo"please login";
exit;
}

Share this post


Link to post
Share on other sites
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]  <?php
if($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]

Share this post


Link to post
Share on other sites
i dont see any error on that line try updating the code to this
[code]
<?php
if(!$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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

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.