Jump to content

[SOLVED] mysql_num_rows problem


Cory94bailly

Recommended Posts

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:

2cyjhoy.png

 

 

Any help will be appreciated (I am pretty sure that the answer will be something very small that I missed ;))

 

Thanks :D

Link to comment
https://forums.phpfreaks.com/topic/145265-solved-mysql_num_rows-problem/
Share on other sites

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 :D

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.