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 Quote 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"); Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.