simcoweb Posted December 28, 2007 Share Posted December 28, 2007 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 Link to comment https://forums.phpfreaks.com/topic/83454-query-function-producing-non-valid-arugment-error/ Share on other sites More sharing options...
btherl Posted December 28, 2007 Share Posted December 28, 2007 Add this after the call to mysql_query() if ($sel === false) die("mysql_query() failed: " . mysql_error() . "\nQuery: " . $sql . "\n"); Link to comment https://forums.phpfreaks.com/topic/83454-query-function-producing-non-valid-arugment-error/#findComment-424573 Share on other sites More sharing options...
simcoweb Posted December 28, 2007 Author Share Posted December 28, 2007 Ok, thanks! Found the problem with a table spelled incorrectly being summoned in the query Link to comment https://forums.phpfreaks.com/topic/83454-query-function-producing-non-valid-arugment-error/#findComment-424579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.