Warning: mysql_num_rows(): supplied argument is not a valid MySQL result

Hello all.

I have a website which is giving me the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/pwoconte/public_html/classes/db.inc.php on line 54
MySQL Error Occured

The code for the file in question is below. Line 54 has been bolded:

function select($query, $maxRows=0, $pageNum=0)
{
$this->query = $query;
// start limit if $maxRows is greater than 0
if($maxRows>0)
{
$startRow = $pageNum * $maxRows;
$query = sprintf("%s LIMIT %d, %d", $query, $startRow, $maxRows);
}

	$result = mysql_query($query, $this->db); 		
	[b]$count  = mysql_num_rows($result);[/b]
	
	if ($this->error()) die($this->debug());

	$output=false;
	
	if( $count != 0){
	for ($n=0; $n < $count; $n++)
	{

The page was displaying fine for the last 4 weeks, and unfortunately, programming is not my thing. It is a photography contest site. The page is programmed not to show any results until a user has entered 10 contests. We have only had 5 contests so far, so I’m not sure what has caused the problem.

Any help you can provide would be greatly appreciated.

Results of mysql_query was false,
try to print $query
if query are correct, should be a connection problem.

Hi,

Agree to kikesv; something’s wrong either with your query or your database connection. Btw, try to add replace this:

[php]$result = mysql_query($query, $this->db); [/php]

with

[php]
if($this->db){
$result = mysql_query($query, $this->db) or die('Invalid query. '.mysql_error());

}
else{
echo “Unable to connect the database.”;
}
[/php]

Cheers.

Sponsor our Newsletter | Privacy Policy | Terms of Service