Jump to content

query function producing non-valid arugment error


simcoweb

Recommended Posts

I have this function including the query:

 

function getTopRated($limit, $table, $idfield, $namefield){

$result = '';

$sql = "SELECT ratings.rating_id,".$table.".".$namefield." as thenamefield,ROUND(AVG(ratings.rating_num),2) as rating 
		FROM ratings,".$table." WHERE ".$table.".".$idfield." = ratings.rating_id GROUP BY rating_id 
		ORDER BY rating DESC LIMIT ".$limit."";

$sel = mysql_query($sql);

$result .= '<ul class="topRatedList">'."\n";

while($data = mysql_fetch_assoc($sel)){
	$result .= '<li>'.$data['thenamefield'].' ('.$data['rating'].')</li>'."\n";
}

$result .= '</ul>'."\n";

return $result;

}

 

Returning this error on line 187 which is the 'while($data = mysql_fetch_assoc($sel))' statement:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\star_rating\includes\rating_functions.php on line 187

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.