Chendyboi Posted June 3, 2013 Share Posted June 3, 2013 I am trying to limit my table results to 10 when my url is /table.php?limit=10 the code that i am using is as follows: if(!isset($_GET['limit']) && $_GET['limit'] == '10') { $fetch = mysql_query("SELECT * FROM (table name) LIMIT 0, 10")or die(mysql_error()); } Could someone help me on where i am going wrong. Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 3, 2013 Share Posted June 3, 2013 Your code says: If the limit is not set, and the limit is equal to 10 (a condition that can never happen), then fetch ten rows. Your code SHOULD SAY: if the limit is set cast the limit to an integer, then fetch that many rows. Quote Link to comment Share on other sites More sharing options...
Chendyboi Posted June 3, 2013 Author Share Posted June 3, 2013 How would i go about doing that? Could you put it into code context or a link to a site that explains it? Quote Link to comment Share on other sites More sharing options...
davidannis Posted June 3, 2013 Share Posted June 3, 2013 (edited) What Jessica said is do something like this: //Note: removed ! in the line below if(isset($_GET['limit'])) { $num_rows=intval($_GET['limit'] ) ; //cast to an integer - makes it work for any number of rows $fetch = mysql_query("SELECT * FROM (table name) LIMIT 0, $num_rows")or die(mysql_error()); } also needed to remove the test for if limit was 10 Edited June 3, 2013 by davidannis Quote Link to comment Share on other sites More sharing options...
Chendyboi Posted June 4, 2013 Author Share Posted June 4, 2013 Freak Dr. this is still not working Quote Link to comment Share on other sites More sharing options...
mikosiko Posted June 4, 2013 Share Posted June 4, 2013 Post the code that you have and explain clearly what means "still not working" Quote Link to comment Share on other sites More sharing options...
davidannis Posted June 4, 2013 Share Posted June 4, 2013 mikosiko is right. You need to post code. Without seeing any code my best guesses are that you need an actual table name where you have (table name) in your select, you don't have a valid connection to the database, or you are not retrieving and displaying the results after the mysql_query. Quote Link to comment 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.