Cory94bailly Posted February 15, 2009 Share Posted February 15, 2009 Hey, long time.. No see everybody Here's my error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/cory/htdocs/massattack/includes/pages/news.php on line 10 News.php, Lines 6-16: $query = "SELECT * FROM $news_tablename ORDER BY $news_sticky, $news_id ASC"; $result = mysql_query($query) or die(mysql_error()); function printNews($result) { if ( mysql_num_rows($result) < 1 ) //LINE 10 { echo "<h1>Nothing new...</h1>"; } else { echo "<table>\n"; As you can see, " if ( mysql_num_rows($result) < 1 )" is line 10. Now in the config.php, I have those variables defined: //Mysql News Variables $news_tablename = "MASSattack"; $news_id = "news_id"; $news_title = "news_title"; $news_subject = "news_subject"; $news_sticky = "news_sticky"; And lastly, here is what my mysql db looks like: Any help will be appreciated (I am pretty sure that the answer will be something very small that I missed ) Thanks Link to comment https://forums.phpfreaks.com/topic/145265-solved-mysql_num_rows-problem/ Share on other sites More sharing options...
genericnumber1 Posted February 15, 2009 Share Posted February 15, 2009 Can you show us all of the code between where you set $result and where you call the printNews() function? Link to comment https://forums.phpfreaks.com/topic/145265-solved-mysql_num_rows-problem/#findComment-762584 Share on other sites More sharing options...
Cory94bailly Posted February 15, 2009 Author Share Posted February 15, 2009 Can you show us all of the code between where you set $result and where you call the printNews() function? That is it but for extra info, here's the whole script: <?php if (!defined('admin')) { die("Hacking Attempt."); } require('/home/cory/htdocs/massattack/includes/config.php'); $query = "SELECT * FROM $news_tablename ORDER BY $news_sticky, $news_id ASC"; $result = mysql_query($query) or die(mysql_error()); function printNews($result) { if ( mysql_num_rows($result) < 1 ) { echo "<h1>Nothing new...</h1>"; } else { echo "<table>\n"; //echo "-------------------------------------------------------------------------"; while($news = mysql_fetch_assoc($result)) { $sticky = ($news['$news_sticky'] == 'y') ? "<font color='red'><u>Announcement:</u></font> " : ''; echo <<<HTML <tr> <th>{$sticky}<b>{$news['title']}</b> -------------------------------------------------------------------------<br /></th> </tr> <tr> <td>{$news['$news_subject']}</td> </tr> HTML; } echo "\n</table><br />"; } } printNews($result1); // Non-sticky News ?> Sorry about some of the "//"d out parts, I'm testing Link to comment https://forums.phpfreaks.com/topic/145265-solved-mysql_num_rows-problem/#findComment-762586 Share on other sites More sharing options...
genericnumber1 Posted February 15, 2009 Share Posted February 15, 2009 Woops, simple, but easy to miss mistake: printNews($result1); should be printNews($result); Link to comment https://forums.phpfreaks.com/topic/145265-solved-mysql_num_rows-problem/#findComment-762593 Share on other sites More sharing options...
Cory94bailly Posted February 15, 2009 Author Share Posted February 15, 2009 Woops, simple, but easy to miss mistake: printNews($result1); should be printNews($result); Ah I knew it would be something stupid! Well I recently changed a bit in this script, forgot that part. Thanks /solved Link to comment https://forums.phpfreaks.com/topic/145265-solved-mysql_num_rows-problem/#findComment-762596 Share on other sites More sharing options...
genericnumber1 Posted February 15, 2009 Share Posted February 15, 2009 Yup, all it takes is an extra set of eyes sometimes. Link to comment https://forums.phpfreaks.com/topic/145265-solved-mysql_num_rows-problem/#findComment-762600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.