0

我正在制作一个页面,其中将有表格(每个表格都在一个字段集中),并且可以选择编辑或删除记录。我添加了分页,以防表格太大而无法容纳页面。唯一的问题是(我是初学者)当我转到下一页时,所有表格都转到下一页。是否可以按字段集进行分页?

这是我到目前为止所拥有的:(它的巨大代码,我只为一张桌子放了一部分)

指数:

<?php

    include("pagination2.php"); 


?>

     <div id="pagination">
     <div id="pagiCount">


<html> 
<head>
<nav>
    <ul>
    <li><a href="Index.php">Home</a>
    <li><a href="Inventory.php">Inventory</a>
    <li><a href="Categories.php">Categories</a>
    <li><a href="Sales.php">Sales</a>
    <li><a href="Customers.php">Customers</a></a>
    <li><a href="Reports.php">Reports</a>
    <li><a href="#top">Edit</a></a>
    <li><a href="Remove.php">Remove</a></a>

    </ul>
</nav>

</br></br></br></br>

  <link rel="stylesheet" href="Styles.css">
  </link>

</head>
<fieldset>
<?php
        include_once('Connect2db.php');
        if(isset($_POST['Categorie1'])) {
        $Categorie = $_POST['Categorie1'];

        if(mysql_query("INSERT INTO bcd VALUES('','$Categorie1')"))
        echo "successful!";
        else
        echo "Please try again";
        } 

        $res = mysql_query("SELECT * FROM bcd");

?>


<h1> Lijst met Categories..</h1>

<?php
        while( $row = mysql_fetch_array($res) )
        echo "$row[ID]. $row[Categorie1] <a href='Edit.php?edit=$row[ID]'>edit</a><br />";
?>

<br/>

 <?php
                if(isset($pages))
                {  
                    if($pages > 1)        
                    {    if($cur_page > $num_links)     ///////////to take to page 1 //////////
                        {   $dir = "first";
                            echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.(1).'">'.$dir.'</a> </span>';
                        }
                       if($cur_page > 1) 
                        {
                            $dir = "prev";
                            echo '<span id="prev"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page-1).'">'.$dir.'</a> </span>';
                        }                 

                        for($x=$start ; $x<=$end ;$x++)
                        {

                            echo ($x == $cur_page) ? '<strong>'.$x.'</strong> ':'<a href="'.$_SERVER['PHP_SELF'].'?page='.$x.'">'.$x.'</a> ';
                        }
                        if($cur_page < $pages )
                        {   $dir = "next";
                            echo '<span id="next"> <a href="'.$_SERVER['PHP_SELF'].'?page='.($cur_page+1).'">'.$dir.'</a> </span>';
                        }
                        if($cur_page < ($pages-$num_links) )
                        {   $dir = "last";

                            echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$pages.'">'.$dir.'</a> '; 
                        }   
                    }
                }
    ?>
        </div>
    </div>
</fieldset>
<fieldset>

分页:

<?php


$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  // select database
  mysql_select_db("inventarisdb", $con); ////provide database name

 $query = mysql_query("SELECT * FROM bcd");
 $total_rows = mysql_num_rows($query);

 $base_url = 'https://localhost/pagi/';
  $per_page = 7;                           //number of results to shown per page 
  $num_links = 8;                           // how many links you want to show
  $total_rows = $total_rows; 
  $cur_page = 1;                           // set default current page to 1

if(isset($_GET['page']))
    {
      $cur_page = $_GET['page'];
      $cur_page = ($cur_page < 1)? 1 : $cur_page;            //if page no. in url is less then 1 or -ve
    }

  $offset = ($cur_page-1)*$per_page;                //setting offset

  $pages = ceil($total_rows/$per_page);              // no of page to be created    

 $start = (($cur_page - $num_links) > 0) ? ($cur_page - ($num_links - 1)) : 1;
    $end   = (($cur_page + $num_links) < $pages) ? ($cur_page + $num_links) : $pages;

 $res = mysql_query("SELECT * FROM bcd LIMIT ".$per_page." OFFSET ".$offset);

 mysql_close($con);
 ?>

请告诉我是否可以按字段集进行分页,以及我尝试实现此目的的方法是否正确。也欢迎提供教程或示例的链接以实现我想要的。提前谢谢你!

4

0 回答 0