I’m working for a page where it shows a tables from database. Let’s say I have 100 rows. How to show 21st-30th row?
In the table, there’s some fields, not only email, name, and description. So, I used mysqli_fetch_assoc
for($num=21;$num<=30;$num++){
$row=mysqli_fetch_assoc($result);
echo "<tr>";
echo "<td>".$num."</td>";
echo "<td>".$row['email']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['description']."</td>";
echo "</tr>";
}
The $num
shows the desired number but the table itself shows the data from 1st-10th. I want it shows the data from 21st-30th
3
Answers
Two possibilites you can doing this way
First
SELECT * from MYTABLE LIMIT 20, 10
Second
Please, try with sql query, where you defined limit of rows like start from row no to end of row no. I wrote one sql query at bellow:
Syntax:
Example:
You can already fix your code with sql queries (for faster performance) adding LIMIT 20, 10 (get 10 records beginning with row 21)
but if you have other logic to be applied on your code (as if your displaying dynamic records)
other thing you might consider is using foreach