我有一个数据库,我试图通过PHP显示进行编辑。在主页面上,我只想显示表格的前15行,然后让用户点击以生成更多的表格行。
<?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();
?>
答案 0 :(得分:4)
使用LIMIT
:
"SELECT uid, title, description, tblFacilityHrsDateTimes.* FROM tblFacilityHrs LEFT JOIN tblFacilityHrsDateTimes ON tblFacilityHrs.uid = tblFacilityHrsDateTimes.owner_uid ORDER BY tblFacilityHrs.title LIMIT 15"
答案 1 :(得分:2)
查看limit
语法in this manual page。 select * from table limit 0,15
将返回以offset 0(第一行)开头的15行。对于第二页,您使用limit 15, 15
获取第16-30行,然后使用limit 30,15
,依此类推。
答案 2 :(得分:2)
你需要看看Paging。本教程可能有所帮助:http://www.php-mysql-tutorial.com/wikis/php-tutorial/paging-using-php.aspx
答案 3 :(得分:1)
可能你正在寻找分页,这可以通过mysql LIMIT
来完成像这样的东西
$result = $mysqli->query("SELECT uid, title, description, tblFacilityHrsDateTimes.* FROM tblFacilityHrs LEFT JOIN tblFacilityHrsDateTimes ON tblFacilityHrs.uid = tblFacilityHrsDateTimes.owner_uid ORDER BY tblFacilityHrs.title LIMIT 15, $page ")
$ page用于抵消
以下是一些创建自定义分页的教程