gergy008 Posted August 20, 2009 Share Posted August 20, 2009 Ok. I'm making a function that returns a string (Which gets echoed by the line that calls it). I want the string to say how many messages a user has. Now I have this up to now, But I have no idea how to get it to work. I need the $results2 variable to say the amount of messages the SQL query found. How do I go abouts this? Thanks in advance! $sql="SELECT cash FROM message WHERE login='".$_SESSION["login"]."' and read='false'"; // OREDER BY id DESC is order result by descending $results = mysql_query($sql); $arr = mysql_fetch_row($results); $results2 = $arr[0]; return"<FONT COLOR='3366CC'> $results2 </FONT> new messages!"; Link to comment https://forums.phpfreaks.com/topic/171086-solved-help-finding-how-many-values-found-in-an-array/ Share on other sites More sharing options...
trq Posted August 20, 2009 Share Posted August 20, 2009 $results2 = mysql_num_rows($results); Link to comment https://forums.phpfreaks.com/topic/171086-solved-help-finding-how-many-values-found-in-an-array/#findComment-902263 Share on other sites More sharing options...
gergy008 Posted August 20, 2009 Author Share Posted August 20, 2009 After a long wait... I got Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/vhosts/www.gergy.info/functions.php on line 482 for this function: function getmsg(){ if(isset($_SESSION["loggedIn"])){ global $link; $sql="SELECT * FROM message WHERE to='".$_SESSION["login"]."' and read='false'"; // OREDER BY id DESC is order result by descending $results = mysql_query($sql); $results2 = mysql_num_rows($results); return"<FONT COLOR='3366CC'> $results2 </FONT> new messages!"; } } Link to comment https://forums.phpfreaks.com/topic/171086-solved-help-finding-how-many-values-found-in-an-array/#findComment-902267 Share on other sites More sharing options...
trq Posted August 20, 2009 Share Posted August 20, 2009 That's means your query is failing, and your not performing any error handling to handle it. Link to comment https://forums.phpfreaks.com/topic/171086-solved-help-finding-how-many-values-found-in-an-array/#findComment-902272 Share on other sites More sharing options...
gergy008 Posted August 20, 2009 Author Share Posted August 20, 2009 That's means your query is failing, and your not performing any error handling to handle it. Ah yes... I forgot. It says I have incorrect syntax? But I see no incorrect syntax here: " SELECT * FROM message WHERE to=' ".$_SESSION["login"]." ' AND read='0' " Read is a bool value by the way. I added spaces after and before the quotes to make it neater to read. Link to comment https://forums.phpfreaks.com/topic/171086-solved-help-finding-how-many-values-found-in-an-array/#findComment-902276 Share on other sites More sharing options...
gergy008 Posted August 20, 2009 Author Share Posted August 20, 2009 I got it... I needed to use backticks (`) on the 'to' and 'read' fields. Link to comment https://forums.phpfreaks.com/topic/171086-solved-help-finding-how-many-values-found-in-an-array/#findComment-902279 Share on other sites More sharing options...
TeNDoLLA Posted August 20, 2009 Share Posted August 20, 2009 That is because both READ and TO are reserved words in MySQL syntax. Link to comment https://forums.phpfreaks.com/topic/171086-solved-help-finding-how-many-values-found-in-an-array/#findComment-902290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.