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 Link to comment https://forums.phpfreaks.com/topic/60305-select-only-rows-where-certain-field-is-empty/ 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/60305-select-only-rows-where-certain-field-is-empty/#findComment-299997 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/60305-select-only-rows-where-certain-field-is-empty/#findComment-300001 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 Link to comment https://forums.phpfreaks.com/topic/60305-select-only-rows-where-certain-field-is-empty/#findComment-300275 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. Link to comment https://forums.phpfreaks.com/topic/60305-select-only-rows-where-certain-field-is-empty/#findComment-300284 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=' ';"; Link to comment https://forums.phpfreaks.com/topic/60305-select-only-rows-where-certain-field-is-empty/#findComment-300287 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=' ';"; Link to comment https://forums.phpfreaks.com/topic/60305-select-only-rows-where-certain-field-is-empty/#findComment-300291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.