亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Affichage du produit du didacticiel de site Web d'entreprise de développement PHP (2)

Dans le cours précédent, nous avons complété l'effet de pagination des actualités

Nous pouvons donc copier le code de pagination dans la section précédente puis changer le nom de la table

Le code est le suivant :

<?php
    require_once('conn.php'); //連接數(shù)據(jù)庫(kù)
    $page=isset($_GET['page']) ?$_GET['page'] :1 ;//接收頁(yè)碼
    $page=!empty($page) ? $page :1;
    $table_name="product";//查取表名設(shè)置
    $perpage=4;//每頁(yè)顯示的數(shù)據(jù)個(gè)數(shù)
    //最大頁(yè)數(shù)和總記錄數(shù)
    $total_sql="SELECT count(*) from $table_name";
    $total_result =mysql_query($total_sql);
    $total_row=mysql_fetch_row($total_result);
    $total = $total_row[0];//獲取最大頁(yè)碼數(shù)
    $total_page = ceil($total/$perpage);//向上整數(shù)
    //臨界點(diǎn)
    $page=$page>$total_page ? $total_page:$page;//當(dāng)下一頁(yè)數(shù)大于最大頁(yè)數(shù)時(shí)的情況
    //分頁(yè)設(shè)置初始化
    $start=($page-1)*$perpage;
    $sql = "SELECT * from product order by id desc limit $start,$perpage";
    $info = mysql_query($sql);    
    //$sql = "select * from product order by id desc"; //查詢user表中的數(shù)據(jù)
    //$info = mysql_query($sql);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>展示用戶列表</title>
    <style type="text/css">
        .top{height:30px;line-height:30px;float:right;margin-right:15px;}
        .top a{color:red;text-decoration:none;}
        .cont{width:100%;height:300px;float:left;}
        .cont_ct{float:left;}
        table{width:100%;border:1px solid #eee;text-align:center;}
        th{background:#eee;height:30px;}
        td{width:200px;height:70px;}
    </style>
</head>
<body>
    <div class="top"><a href="addpro.php">添加產(chǎn)品</a></div>

    <div class="cont">
        <table cellspacing="0" cellpadding="0" border="1">
            <tr>
                <th>ID</th>
                <th>名稱</th>
                <th>圖片</th>
                <th>價(jià)格</th>
                <th>操作</th>
            </tr>
            <?php
                while($row = mysql_fetch_array($info)){
            ?>
            <tr>
                <td><?php echo $row['id'];?></td>
                <td><?php echo $row['title'];?></td>
                <td><img src="../uploads/<?php echo $row['imgname'];?>" width="50" height="50"></td>
                <td><?php echo $row['price'];?></td>
                <td>
                    <a href="modifypro.php?id=<?php echo $row['id'];?>">修改</a>
                    <a href="delproduct.php?id=<?php echo $row['id'];?>">刪除</a>
                </td>
            </tr>
            <?php
                }
            ?>
            <tr>
                <td colspan="5">
                <a href="<?php echo "$_SERVER[PHP_SELF]?page=1"?>">首頁(yè)</a>
                <a href="<?php echo "$_SERVER[PHP_SELF]?page=".($page-1)?>">上一頁(yè)</a><a href="<?php echo "$_SERVER[PHP_SELF]?page=".($page+1)?>">下一頁(yè)</a>
                <a href="<?php echo "$_SERVER[PHP_SELF]?page={$total_page}"?>">末頁(yè)</a>
                </td>
            </tr>
        </table>
    </div>
</body>
</html>

De cette fa?on, nous avons complété l'effet de pagination

Formation continue
||
<?php require_once('conn.php'); //連接數(shù)據(jù)庫(kù) $page=isset($_GET['page']) ?$_GET['page'] :1 ;//接收頁(yè)碼 $page=!empty($page) ? $page :1; $table_name="product";//查取表名設(shè)置 $perpage=4;//每頁(yè)顯示的數(shù)據(jù)個(gè)數(shù) //最大頁(yè)數(shù)和總記錄數(shù) $total_sql="SELECT count(*) from $table_name"; $total_result =mysql_query($total_sql); $total_row=mysql_fetch_row($total_result); $total = $total_row[0];//獲取最大頁(yè)碼數(shù) $total_page = ceil($total/$perpage);//向上整數(shù) //臨界點(diǎn) $page=$page>$total_page ? $total_page:$page;//當(dāng)下一頁(yè)數(shù)大于最大頁(yè)數(shù)時(shí)的情況 //分頁(yè)設(shè)置初始化 $start=($page-1)*$perpage; $sql = "SELECT * from product order by id desc limit $start,$perpage"; $info = mysql_query($sql); //$sql = "select * from product order by id desc"; //查詢user表中的數(shù)據(jù) //$info = mysql_query($sql); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>展示用戶列表</title> <style type="text/css"> .top{height:30px;line-height:30px;float:right;margin-right:15px;} .top a{color:red;text-decoration:none;} .cont{width:100%;height:300px;float:left;} .cont_ct{float:left;} table{width:100%;border:1px solid #eee;text-align:center;} th{background:#eee;height:30px;} td{width:200px;height:70px;} </style> </head> <body> <div class="top"><a href="addpro.php">添加產(chǎn)品</a></div> <div class="cont"> <table cellspacing="0" cellpadding="0" border="1"> <tr> <th>ID</th> <th>名稱</th> <th>圖片</th> <th>價(jià)格</th> <th>操作</th> </tr> <?php while($row = mysql_fetch_array($info)){ ?> <tr> <td><?php echo $row['id'];?></td> <td><?php echo $row['title'];?></td> <td><img src="../uploads/<?php echo $row['imgname'];?>" width="50" height="50"></td> <td><?php echo $row['price'];?></td> <td> <a href="modifypro.php?id=<?php echo $row['id'];?>">修改</a> <a href="delproduct.php?id=<?php echo $row['id'];?>">刪除</a> </td> </tr> <?php } ?> <tr> <td colspan="5"> <a href="<?php echo "$_SERVER[PHP_SELF]?page=1"?>">首頁(yè)</a> <a href="<?php echo "$_SERVER[PHP_SELF]?page=".($page-1)?>">上一頁(yè)</a><a href="<?php echo "$_SERVER[PHP_SELF]?page=".($page+1)?>">下一頁(yè)</a> <a href="<?php echo "$_SERVER[PHP_SELF]?page={$total_page}"?>">末頁(yè)</a> </td> </tr> </table> </div> </body> </html>
soumettreRéinitialiser le code