Mutley Posted July 6, 2007 Share Posted July 6, 2007 Error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 9 Code: <table align="left" width="80%"> <?php require_once("connection.php"); $query = "SELECT id, name, surname FROM profiles ORDER BY surname, name"; $result = mysql_query($query); if(mysql_num_rows($result)!=0) { while(list($id, $name, $surname) = mysql_fetch_row($result)) { ?> <tr> <td align="left"><a href="profiles.php?id=<?=$id?>"><?=$surname?>, <?=$name?></a></td> </tr> <?php } } else { echo "No profiles were found"; } ?> </table> Anyone know what the problem is? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/ Share on other sites More sharing options...
NArc0t1c Posted July 6, 2007 Share Posted July 6, 2007 I don't think you can count an ordered result. Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291093 Share on other sites More sharing options...
AndyB Posted July 6, 2007 Share Posted July 6, 2007 if(mysql_num_rows($result)!=0) { should be if(mysql_num_rows($query)!=0) { Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291096 Share on other sites More sharing options...
Mutley Posted July 6, 2007 Author Share Posted July 6, 2007 if(mysql_num_rows($result)!=0) { should be if(mysql_num_rows($query)!=0) { Nope, same error. ??? Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291110 Share on other sites More sharing options...
MemphiS Posted July 6, 2007 Share Posted July 6, 2007 Make life easier for your self... $query = "SELECT id, name, surname FROM profiles ORDER BY surname, name"; $rows = mysql_num_rows($query); $result = mysql_query($query); if($rows > 0) { Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291114 Share on other sites More sharing options...
MemphiS Posted July 6, 2007 Share Posted July 6, 2007 <table align="left" width="80%"> <?php require_once("connection.php"); $query = mysql_query("SELECT id, name, surname FROM profiles ORDER BY surname, name"); if(mysql_num_rows($query)>0) { while(list($id, $name, $surname) = mysql_fetch_row($query)) { ?> <tr><td align="left"><a href="profiles.php?id=<?=$id?>"><?=$surname?>, <?=$name?></a></td></tr> <?php } }else{echo "No profiles were found";} ?> </table> Try the above... Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291116 Share on other sites More sharing options...
Mutley Posted July 6, 2007 Author Share Posted July 6, 2007 Same error, line 6 there. Thanks for the help so far. Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291159 Share on other sites More sharing options...
MemphiS Posted July 6, 2007 Share Posted July 6, 2007 <table align="left" width="80%"> <?php require_once("connection.php"); $query = mysql_query("SELECT id, name, surname FROM profiles ORDER BY surname, name"); $numrows = mysql_num_rows($query); if ($numrows>0){ while(list($id, $name, $surname) = mysql_fetch_row($query)) { ?> <tr><td align="left"><a href="profiles.php?id=<?=$id?>"><?=$surname?>, <?=$name?></a></td></tr> <?php } }else{echo "No profiles were found";} ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291162 Share on other sites More sharing options...
Mutley Posted July 6, 2007 Author Share Posted July 6, 2007 Same error. Line 5. ??? I wonder what's causing it, something other to the code possibly? Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291170 Share on other sites More sharing options...
MemphiS Posted July 6, 2007 Share Posted July 6, 2007 This isnt tested... This is how i would code it.. <table align="left" width="80%"> <?php require_once("connection.php"); $query = mysql_query("SELECT `id` , `name` , `surname` FROM `profiles` ORDER BY surname, name DESC"); $queryRows = mysql_num_rows($query); if ($queryRows > 0){ while ($queryFetch = mysql_fetch_row($query)){ echo("<tr><td align='left'><a href='profiles.php?id=$queryFetch[0]'>$queryFetch[2], $queryFetch[1]</a></td></tr>"); } }else{ echo("<tr><td align='center'>No Profiles Found!</td></tr>"); } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291179 Share on other sites More sharing options...
Mutley Posted July 6, 2007 Author Share Posted July 6, 2007 Nope, still no luck. I think my head might just explode, this is really irritating, lol. Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291181 Share on other sites More sharing options...
MemphiS Posted July 6, 2007 Share Posted July 6, 2007 hmm.. Whats the Error msg ? Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291185 Share on other sites More sharing options...
no_one Posted July 6, 2007 Share Posted July 6, 2007 Try printing mysql_error() and mysql_errno() ? The resource probably wouldn't be valid if the query failed. I think *cough*. Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291191 Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 Are you sure your MySQL is returning anything at all and not just throwing errors? Hmmmm =) table align="left" width="80%"> <?php require_once("connection.php"); $query = "SELECT id, name, surname FROM profiles ORDER BY surname, name"; $result = mysql_query($query) OR DIE("SQL ERROR FOR QUERY:" . $query . "<br />ERROR: " . mysql_error()); if(mysql_num_rows($result)!=0) { while(list($id, $name, $surname) = mysql_fetch_row($result)) { ?> <tr> <td align="left"><a href="profiles.php?id=<?=$id?>"><?=$surname?>, <?=$name?></a></td> </tr> <?php } } else { echo "No profiles were found"; } ?> </table> Post the error results. Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291192 Share on other sites More sharing options...
Mutley Posted July 6, 2007 Author Share Posted July 6, 2007 It says: SQL ERROR FOR QUERY:SELECT id, name, surname FROM profiles ORDER BY surname, name ERROR: No database selected My connection.php: require_once("config.php"); $connection = mysql_connect($host, $user, $pwd) or die("&error1=".mysql_error()); mysql_select_db($db, $connection); My config.php: $host = "localhost"; $user = "yorkrufc_rufc"; $pwd = "";//removed $db = "yorkrufc_rufc"; So it should connect. ??? Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291196 Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 require_once("config.php"); $connection = mysql_connect($host, $user, $pwd) or die("&error1=".mysql_error()); mysql_select_db($db, $connection) OR DIE("Selection Error:" . mysql_error() . "<br /> For Database: $db"); See what that gets ya. Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291200 Share on other sites More sharing options...
Mutley Posted July 6, 2007 Author Share Posted July 6, 2007 Fixed it, my FTP was in a stupid "skip not overwrite" mode. Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/58684-solved-help-warning-mysql_num_rows/#findComment-291225 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.