I have a database I'm trying to display for edit through PHP. On the main page I want to show only the first 15 rows of the table then have the user click to generate more table rows.
<?php
include('../config.php');
$result = $mysqli->query("SELECT uid, title, description, tblFacilityHrsDateTimes.* FROM tblFacilityHrs LEFT JOIN tblFacilityHrsDateTimes ON tblFacilityHrs.uid = tblFacilityHrsDateTimes.owner_uid ORDER BY tblFacilityHrs.title") or die($mysqli->error);
while($row =$result->fetch_assoc()){
extract ($row);
echo "<tr>";
echo "<td> {$id} </td>"; //hide when finished
echo "<td> {$title} </td>";
echo "<td> {$description} </td>";
echo "<td> {$startEventDate} </td>";
echo "<td> {$endEventDate} </td>";
echo "<td> {$startTime} </td>";
echo "<td> {$endTime} </td>";
echo "<td> {$days} </td>";
echo "<td> {$recurrence} </td>";
echo "<td> {$finalDate} </td>";
echo "<td>";
echo "<a class=\"buttons\" href=edit.php?id={$id}&uid={$uid}>Edit</a><span class='icon'></span></a>
";
echo " / ";
echo "<a class=\"buttons\" href='javascript: Confirm()'>Delete</a>";
echo "</td>";
echo "</tr>";
echo "</div>";
}
echo "</table>";
$result->free();
$mysqli->close();
?>
Check out the
limit
syntax in this manual page.select * from table limit 0,15
will return 15 rows starting with offset 0 (the first row). For the second page you'd uselimit 15, 15
to get rows 16-30, thenlimit 30,15
and so on.Use
LIMIT
:You need to look at Paging. This tutorial may help: http://www.php-mysql-tutorial.com/wikis/php-tutorial/paging-using-php.aspx
Probably you are looking for Pagination, this can be done through mysql LIMIT
Something like that
Where $page is for offset
Here are few tutorial for creating custom pagination
Pagination of MySQL Query Results
Pagination - what it is and how to do it