nadz Posted July 17, 2007 Share Posted July 17, 2007 Basically i need to select the rows from a table where the user is "$curr_user" and the "seen" field is empty. Then i want to count the rows and use the count in a javascript alert. Heres what i got so far: <?php $result = mysql_query($query = "SELECT * FROM user WHERE user=''.$curr_user.'' AND seen=''") or trigger_error(mysql_error()."<PRE>".$query."</PRE>", E_USER_ERROR); $num = mysql_num_rows($result) if($num > 0) { <script language="Javascript"> alert ("You have $num new messages") </script> } ?> can anyone see whats wrong? any help appreciated Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 17, 2007 Share Posted July 17, 2007 No offense, but that code is full of errors. At the very least you should have received some type of error on screen. You should always post the error messages in these situations. Try this: <?php $query = "SELECT count(*) as count FROM user WHERE user='".$curr_user."' AND seen='' GROUP BY user"; $result = mysql_query($query) or trigger_error(mysql_error()."<PRE>".$query."</PRE>", E_USER_ERROR); if(mysql_num_rows($result)) { $record = mysql_fetch_assoc($result); echo "<script language=\"Javascript\">\n"; echo "alert ('You have $num new messages');\n"; echo "</script>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted July 17, 2007 Share Posted July 17, 2007 <?php $query = "SELECT count(*) as count FROM user WHERE user='".$curr_user."' AND seen='' GROUP BY user"; $result = mysql_query($query) or trigger_error(mysql_error()."<PRE>".$query."</PRE>", E_USER_ERROR); if(mysql_num_rows($result)) { $record = mysql_fetch_assoc($result); echo "<script language=\"Javascript\">\n"; echo "alert ('You have $num new messages');\n"; echo "</script>\n"; } ?> This code was good but there was no initialization for the variable $num So try this: <?php $query = "SELECT count(*) as count FROM user WHERE user='".$curr_user."' AND seen='' GROUP BY user"; $result = mysql_query($query) or trigger_error(mysql_error()."<PRE>".$query."</PRE>", E_USER_ERROR); $num=mysql_num_rows($result); if($num)) { $record = mysql_fetch_assoc($result); echo "<script language=\"Javascript\">\n"; echo "alert ('You have $num new messages');\n"; echo "</script>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
nadz Posted July 17, 2007 Author Share Posted July 17, 2007 hi, thanks for the help guys. im getting this error with the code qbove me. any ideas? Parse error: syntax error, unexpected ')' in /home/.loekie/nexman/D******.co.uk/file/templates_c/%%112%%1125780542_footer.html.php on line 73 Quote Link to comment Share on other sites More sharing options...
nadz Posted July 17, 2007 Author Share Posted July 17, 2007 ive fixed the error, now all the code is right i just need to work out how to use it within my sites header or footer. Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 17, 2007 Share Posted July 17, 2007 $query3="SELECT * FROM np1 WHERE Clinton='';"; ok, in the empty fields of your table, is null written it. if not, than remove the word null from above...it will look like this : $query3="SELECT * FROM np1 WHERE Clinton=' ';"; Quote Link to comment Share on other sites More sharing options...
jd2007 Posted July 17, 2007 Share Posted July 17, 2007 $query3="SELECT * FROM np1 WHERE Clinton='';"; ok, in the empty fields of your table, is null written it. if not, than remove the word null from above...it will look like this : $query3="SELECT * FROM np1 WHERE Clinton=' ';"; 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.