分页不起作用

时间:2017-02-28 05:56:26

标签: php mysql

我要为我的会员页面做一个分页,我有一个从1到8创建的8个分页编号,这样当我点击每个页面时,它应该只显示1行特定的数据库表,数据库表由8行,但在我的代码中,当我点击,正确的页码正在通过,但它没有更新和显示特定选择的分页行,请你帮我解决这个问题。 members.php

<?php
include('assets/page_header.php');
include('db/db.php');
$page="";
if(isset($_GET['page']))
{
$page=$_GET['page'];
}
?>
<html>
<head><title></title>
<style>
h1 {
text-align:center;
}
</style>
</head>
<?php
/*$memno=mysql_real_escape_string($_POST['memno']);
$memname=mysql_real_escape_string($_POST['name']);
    $address=mysql_real_escape_string($_POST['address']);
    $phonenumber=mysql_real_escape_string($_POST['phno']);
    $renewaldate=mysql_real_escape_string($_POST['renewaldate']);
    $maxborrowlimit=mysql_real_escape_string($_POST['maxborrowlimit']);
    $status=mysql_real_escape_string($_POST['status']);*/
    ?>
    <h1>MEMBERS PAGE</h1>

<?php
$str="select * from member LIMIT 1,1 ";
$query1=mysql_query($str);
echo "<table align='center'>";
echo "<tr><th><MemberNumber</th><th>MemberName</th><th>Address</th><th>Phonenumber</th><th>RenewalDate</th><th>MaxBorrowLimit</th><th>Status</th><th colspan=2>Action</th></tr>";
while($query2=mysql_fetch_array($query1))
{
echo "<tr>";
echo "<td>".$query2['memno']."</td>";
echo "<td>".$query2['name']."</td>";
echo "<td>".$query2['address']."</td>";
echo "<td>".$query2['phno']."</td>";
echo "<td>".$query2['renewaldate']."</td>";
echo "<td>".$query2['maxborrowlimit']."</td>";
echo "<td>".$query2['status']."</td>";
echo "<td><button class='button1' data-toggle='tooltip' title='Delete' id=".$query2['memno']." value='delete' name='delete'><img id='image' src='./images/trash.png'/></button></td>";
echo "<td><a id='colour' class='tooltip'  href='membereditform.php?mem_no=".$query2['memno']."'><img id='image' src='./images/small.gif'/><span class='tooltiptext' >Edit</span></a></td>";
echo "</tr>";
}
echo "</table>";
?>
<?php

if($page=="" || $page=='1')
{
$page1=0;
}
else
{
$page1=($page*4)-4;
}
$query1=mysql_query("select * from member");
$count=mysql_num_rows($query1);
$s=$count/1;
echo $s;
echo "<br>";
for($i=1;$i<=$s;$i++)
{
?><a href="members.php?page=<?php echo  $i ?>" style="text-decoration":none,"Text-align":center;><?php echo $i?></a><?php
}
?> 

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码:

<?php
    include('assets/page_header.php');
    include('db/db.php');
?>
<html>
    <head><title></title>
        <style>
            h1 {
                text-align:center;
            }
        </style>
    </head>
    <?php
        /*$memno=mysql_real_escape_string($_POST['memno']);
        $memname=mysql_real_escape_string($_POST['name']);
        $address=mysql_real_escape_string($_POST['address']);
        $phonenumber=mysql_real_escape_string($_POST['phno']);
        $renewaldate=mysql_real_escape_string($_POST['renewaldate']);
        $maxborrowlimit=mysql_real_escape_string($_POST['maxborrowlimit']);
        $status=mysql_real_escape_string($_POST['status']);*/
    ?>
    <h1>MEMBERS PAGE</h1>

    <?php
        $num_rec_per_page = 10;
        if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
        $start_from = ($page-1) * $num_rec_per_page; 
        $str = "select * from member LIMIT $start_from, $num_rec_per_page";
        $query1=mysql_query($str);
        echo "<table align='center'>";
        echo "<tr><th><MemberNumber</th><th>MemberName</th><th>Address</th><th>Phonenumber</th><th>RenewalDate</th><th>MaxBorrowLimit</th><th>Status</th><th colspan=2>Action</th></tr>";
        while($query2=mysql_fetch_array($query1))
        {
            echo "<tr>";
            echo "<td>".$query2['memno']."</td>";
            echo "<td>".$query2['name']."</td>";
            echo "<td>".$query2['address']."</td>";
            echo "<td>".$query2['phno']."</td>";
            echo "<td>".$query2['renewaldate']."</td>";
            echo "<td>".$query2['maxborrowlimit']."</td>";
            echo "<td>".$query2['status']."</td>";
            echo "<td><button class='button1' data-toggle='tooltip' title='Delete' id=".$query2['memno']." value='delete' name='delete'><img id='image' src='./images/trash.png'/></button></td>";
            echo "<td><a id='colour' class='tooltip'  href='membereditform.php?mem_no=".$query2['memno']."'><img id='image' src='./images/small.gif'/><span class='tooltiptext' >Edit</span></a></td>";
            echo "</tr>";
        }
        echo "</table>";
    ?>
    <?php

        $sql = "select * from member"; 
        $rs_result = mysql_query($sql); //run the query
        $total_records = mysql_num_rows($rs_result);  //count number of records
        $total_pages = ceil($total_records / $num_rec_per_page); 

        if($total_records > 0) {
            echo "<a href='members.php?page=1'> ".'<'." </a> "; // Goto 1st page  
        }

        for ($i=1; $i<=$total_pages; $i++) { 
            echo "<a href='members.php?page=".$i."'> ".$i." </a> "; 
        };

        if($total_records > 0) {
            echo "<a href='members.php?page=$total_pages'> ".'>'." </a> "; // Goto last page
        }
    ?>
</html>