Jump to content


Photo

IDK how to ....


  • Please log in to reply
11 replies to this topic

#1 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 21 August 2006 - 09:48 PM

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...
SELECT * FROM `messages` WHERE `to` = '$to' AND `status` = 'no'

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 shortener with advanced, detailed statistics:

http://tyny.us/

#2 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 21 August 2006 - 09:54 PM

$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.";
}
umm try this

#3 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 21 August 2006 - 09:56 PM

Use mysql_num_rows() to find out how many new messages they have. If they have more than 0 new messages, display the New Messages link.

#4 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 21 August 2006 - 10:04 PM

I used this
$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>";
}

and got this error:
Parse error: syntax error, unexpected T_VARIABLE in /home/zyco/public_html/newlayout/main.php on line 32

Link shortener with advanced, detailed statistics:

http://tyny.us/

#5 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 21 August 2006 - 10:15 PM

You're missing a semi-colon on the first line in your code that you showed above.

#6 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 21 August 2006 - 10:17 PM

I aded the semicolon onto
$to = '$_SESSION[username]'
and now i get this error:
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

Link shortener with advanced, detailed statistics:

http://tyny.us/

#7 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 21 August 2006 - 10:34 PM

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];

#8 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 22 August 2006 - 01:21 AM

here is LINES 27 - 47(the whole PHP script)

  <?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>";
}
}
?>

Link shortener with advanced, detailed statistics:

http://tyny.us/

#9 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 22 August 2006 - 01:28 AM

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;
}

#10 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 22 August 2006 - 01:43 AM

I still get the same error:
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

with this as my updated 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>";
}
}
?>

LINE 41 IS:
if(new != "0" ){

Link shortener with advanced, detailed statistics:

http://tyny.us/

#11 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 22 August 2006 - 01:49 AM

i dont see any error on that line try updating the code to this
 <?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>";
}
?>
im pretty sure this will work

#12 techiefreak05

techiefreak05
  • Members
  • PipPipPip
  • Advanced Member
  • 494 posts
  • LocationER, MN

Posted 22 August 2006 - 02:17 AM

ok, i got the problem fixed.. wanna hear the solution, your gonna beat yourself... look, whats wrong with this:
if(new != "0"){

it SHOULD be
if($new != "0"){

haha now go kick yourself :P lmao!
Link shortener with advanced, detailed statistics:

http://tyny.us/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users