webguync Posted March 27, 2008 Share Posted March 27, 2008 I get this error when trying to display data from a MySQL table Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/n/c/u/ncupsetbids/html/templates/RecordManagementTemplate.php on line 11 does this just mean no results are being found? here is the PHP code $result=mysql_query ("SELECT * from upsetsbids ORDER BY HearingID "); $resultCount = mysql_num_rows($result); if ($resultCount > 0) { // make sure we have data to display thanks Link to comment https://forums.phpfreaks.com/topic/98232-please-explain-error/ Share on other sites More sharing options...
wildteen88 Posted March 27, 2008 Share Posted March 27, 2008 No, usually that means there is a problem with your query. To see why your query is failing, add or die(mysql_error()) at the end of the mysql_query call, eg: $result=mysql_query ("SELECT * from upsetsbids ORDER BY HearingID ") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/98232-please-explain-error/#findComment-502606 Share on other sites More sharing options...
cooldude832 Posted March 27, 2008 Share Posted March 27, 2008 to take it one step further you should write queries like <?php $q = "Select * from `upsetbids` order by HearingID"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); ?> That is proper way to debug a query because when it splashes out a mysql error it will also splash out the outputted query so you can quickly see the mistake or take said query into phpmyadmin and modify it to work better as is all to often the case. Link to comment https://forums.phpfreaks.com/topic/98232-please-explain-error/#findComment-502609 Share on other sites More sharing options...
webguync Posted March 27, 2008 Author Share Posted March 27, 2008 thanks, thanks another error now Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/n/c/u/ncupsetbids/html/templates/RecordManagementTemplate.php on line 29 and the current code from line 29: while ($row = mysql_fetch_assoc($q)) { // Display the data from mysql Link to comment https://forums.phpfreaks.com/topic/98232-please-explain-error/#findComment-502619 Share on other sites More sharing options...
cooldude832 Posted March 27, 2008 Share Posted March 27, 2008 well plain and simple because $q isn't a valid mysql resource its a string you need to work on the query resource variable which in my example is $r Link to comment https://forums.phpfreaks.com/topic/98232-please-explain-error/#findComment-502620 Share on other sites More sharing options...
webguync Posted March 27, 2008 Author Share Posted March 27, 2008 doh! stupid error on my part, thanks! Link to comment https://forums.phpfreaks.com/topic/98232-please-explain-error/#findComment-502636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.