Jim R Posted January 31, 2011 Share Posted January 31, 2011 This code works fine without the LIMIT 5, but it lists all the results. With the LIMIT $query = 'SELECT * FROM wp_playerRank WHERE year="2011" LIMIT 5 ORDER BY rankClass ASC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { Here is the error I'm getting: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/jwrbloom/public_html/resources/players/rank2011_top5.php on line 26 Link to comment https://forums.phpfreaks.com/topic/226253-getting-using-a-limit/ Share on other sites More sharing options...
BlueSkyIS Posted January 31, 2011 Share Posted January 31, 2011 LIMIT 5 should be the last part of the SQL Link to comment https://forums.phpfreaks.com/topic/226253-getting-using-a-limit/#findComment-1167937 Share on other sites More sharing options...
PFMaBiSmAd Posted January 31, 2011 Share Posted January 31, 2011 ^^^ And here's the syntax definition that shows that - SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [sTRAIGHT_JOIN] [sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT] [sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS] select_expr [, select_expr ...] [FROM table_references [WHERE where_condition] [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [PROCEDURE procedure_name(argument_list)] [iNTO OUTFILE 'file_name' [CHARACTER SET charset_name] export_options | INTO DUMPFILE 'file_name' | INTO var_name [, var_name]] [FOR UPDATE | LOCK IN SHARE MODE]] Link to comment https://forums.phpfreaks.com/topic/226253-getting-using-a-limit/#findComment-1167940 Share on other sites More sharing options...
kcmakwana Posted January 31, 2011 Share Posted January 31, 2011 $query = 'SELECT * FROM wp_playerRank WHERE year="2011" ORDER BY rankClass ASC LIMIT 5'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { Link to comment https://forums.phpfreaks.com/topic/226253-getting-using-a-limit/#findComment-1167944 Share on other sites More sharing options...
Jim R Posted January 31, 2011 Author Share Posted January 31, 2011 OK...I put it at the end, and while it eliminated the error, I'm not getting any results now. $query = 'SELECT * FROM wp_playerRank WHERE year="2011" ORDER BY rankClass ASC LIMIT 5'; Link to comment https://forums.phpfreaks.com/topic/226253-getting-using-a-limit/#findComment-1167945 Share on other sites More sharing options...
BlueSkyIS Posted January 31, 2011 Share Posted January 31, 2011 make sure the query runs: $results = mysql_query($query) or die(mysql_error()); echo the query and copy/paste into phpmyadmin or other method to test it. remove the limit and test again. etc. Link to comment https://forums.phpfreaks.com/topic/226253-getting-using-a-limit/#findComment-1167947 Share on other sites More sharing options...
Jim R Posted January 31, 2011 Author Share Posted January 31, 2011 I've tried it without the limit, and it works fine. I use that query elsewhere too without the limit. I just added the limit because I'm reproducing a smaller list on my homepage. Link to comment https://forums.phpfreaks.com/topic/226253-getting-using-a-limit/#findComment-1167949 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.