[Solved] SQL to only fetch some rows?


Use this in your query:

LIMIT 24

LIMIT is a MySQL function that selects a particular range of results from your query results. There are basically two ways of using it:

  1. By simply specifying the number of results you want to fetch, like LIMIT 24; or
  2. By specifying another range in the form of LIMIT X, Y. Where X is the beginning and Y is number of rows you want to fetch, like: LIMIT 10,5 that would select the 5 results from row 11 to 15

In your particular case you can simply replace this line:

$query = "SELECT * FROM {$tableObject} {$sort1};";

For:

$query = "SELECT * FROM {$tableObject} {$sort1} LIMIT 24;";

or even:

$query = "SELECT * FROM {$tableObject} {$sort1} LIMIT 0,24;";

For a better understanding about how to use limit, I recommend you to read this page from MySQL manual

3

solved SQL to only fetch some rows?