0
这里我使用get
方法从搜索表单中收集类别和面积值。因此,即时通讯有7个记录到数据库中,我想每个页面只显示4条记录,当用户点击Next按钮时,剩余的记录需要显示,但是这里我的代码只显示数据库的前四条记录,但是当我点击下一个按钮,然后剩余的3条记录没有显示出来。如何使用PHP分页从MySQL数据库中检索到的数据?
考虑area=Mumbai
和category=lawn
。如果只有7个记录到数据库中,然后我想前四拿到显示在第一页,其余3到上点击下一步按钮在同一页..
这里是我的代码:
<?php
$link=mysql_connect("localhost","root","");
mysql_select_db("celebration_db",$link);
$q="select count(*) \"total\" from hallinfo";
$ros=mysql_query($q,$link);
$row=(mysql_fetch_array($ros));
$total=$row['total'];
$dis=4;
$total_page=ceil($total/$dis);
$page_cur=(isset($_GET['page']))?$_GET['page']:1;
$k=($page_cur-1)*$dis;
$category = $_GET['category'];
$area = $_GET['area'];
//$category = 'hall';
//$area = 'nagpur';
echo $category;
echo $area;
$q="select * from hallinfo where category = '$category' AND area = '$area' limit $k,$dis";
//$q="select * from hallinfo limit $k,$dis";
$ros=mysql_query($q,$link);
while($row=mysql_fetch_array($ros))
{
$imageId = $row['id'];
echo '<div id="pattern">';
echo '<table>';
echo '<tr>';
echo '<td colspan="2" width="300px" height="200px">
<img src="image-show.php?id='.$imageId.'">';
echo '</td>';
echo '<td width="150px" height="200px">'.$row['description'];
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>'.$row['rent'];
echo '</td>';
echo '<td>'.$row['capacity'];
echo '</td>';
echo '<td>'.$row['area'];
echo '</td>';
echo '</tr>';
echo '</table>';
echo '</div>';
}
//echo '</table>';
//echo '<br/>';
if($page_cur>1)
{
echo '<a href="pagination.php?page='.($page_cur-1).'" style="cursor:pointer;color:green;" ><input style="cursor:pointer;background-color:green;border:1px black solid;border-radius:5px;width:120px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button" value=" Previous "></a>';
}
else
{
echo '<input style="background-color:green;border:1px black solid;border-radius:5px;width:120px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button" value=" Previous ">';
}
for($i=1;$i<$total_page;$i++)
{
if($page_cur==$i)
{
echo ' <input style="background-color:green;border:2px black solid;border-radius:5px;width:30px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button" value="'.$i.'"> ';
}
else
{
echo '<a href="pagination.php?page='.$i.'"> <input style="cursor:pointer;background-color:green;border:1px black solid;border-radius:5px;width:30px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button" value="'.$i.'"> </a>';
}
}
if($page_cur<$total_page)
{
echo '<a href="pagination.php?page='.($page_cur+1).'"><input style="cursor:pointer;background-color:green;border:1px black solid;border-radius:5px;width:90px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button" value=" Next "></a>';
}
else
{
echo '<input style="background-color:green;border:1px black solid;border-radius:5px;width:90px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button" value=" Next ">';
}
?>