It was some time ago I worked with PHP, MySQL and SQL, so I need some help. In my table I have 44 rows, but I only want to get 24 of them. Before I have just loaded all the rows like in the code below, and now I need some help to modify it to only load 24 rows. Thanks!
$query = "SELECT * FROM {$tableObject} {$sort1};";
$res = $mysqli->query($query);
$row_cnt = mysqli_num_rows($res);
while($row01 = $res->fetch_object()) {
// Some other code here
}
Use this in your query:
LIMIT is a MySQL function that selects a particular range of results from your query results. There are basically two ways of using it:
LIMIT 24; orLIMIT X, Y. WhereXis the beginning andYis number of rows you want to fetch, like:LIMIT 10,5that would select the 5 results from row11to15In your particular case you can simply replace this line:
For:
or even:
For a better understanding about how to use limit, I recommend you to read this page from MySQL manual