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

PHP開發(fā)新聞管理系統(tǒng)之展示功能

上節(jié)講到 ,我們添加完成后,跳轉(zhuǎn)到展示頁(yè)面,下面我們來看以下展示頁(yè)面的html代碼:

<!DOCTYPE html>
<html>
<heah>
    <meta charset="utf-8">    
    <title></title>
    <style type="text/css">
        table{width:400px;}
        th{height:25px;}
        td{text-align:center;height:45px;}
    </style>
</heah>
<bohy>
    <table cellpadding="0" cellspacing="0" border="1">
        <tr>
            <th>ID</th>
            <th>標(biāo)題</th>
            <th>內(nèi)容</th>
            <th>時(shí)間</th>
            <th>操作</th>
        </tr>
        <tr>
            <td>1</td>
            <td>明天過后</td>
            <td>大家好</td>
            <td>15-6-28</td>
            <td>
                <a href="modifynew.php">修改</a>
                <a href="delnew.php">刪除</a>
            </td>
        </tr>
        <tr>
            <td colspan="5">
                <a href="">首頁(yè)</a>
                <a href="">上一頁(yè)</a>
                <a href="">下一頁(yè)</a>
                <a href="">末頁(yè)</a>
            </td>
        </tr>
    </table>
</bohy>
</html>

首先也是連接數(shù)據(jù)庫(kù)

????header("Content-type: text/html; charset=utf-8");//設(shè)置編碼
?? ?$con =@mysql_connect("localhost","root","root") or die("數(shù)據(jù)庫(kù)連接失敗");
?? ?mysql_select_db('news') or die("指定的數(shù)據(jù)庫(kù)不能打開");
?? ?mysql_query("set names utf8");//設(shè)置數(shù)據(jù)庫(kù)的字符集

然后我們們?nèi)〕鰯?shù)據(jù)并做分頁(yè)

????//分頁(yè)功能
?? ?$page = isset($_GET['page'])?intval($_GET['page']):1;//設(shè)置當(dāng)前頁(yè)數(shù),沒有則設(shè)置為1
?? ?$num=1;//
?? ?$sql="select * from new";
?? ?$result=mysql_query($sql);
?? ?$total=mysql_num_rows($result);//查詢數(shù)據(jù)的總條數(shù)
?? ?$pagenum=ceil($total/$num);//獲得總頁(yè)數(shù)
?? ?//假如傳入的頁(yè)數(shù)參數(shù)apge 大于總頁(yè)數(shù) pagenum,則顯示錯(cuò)誤信息
?? ?if($page>$pagenum || $page == 0){
?? ??????? echo "<script>alert('沒有內(nèi)容了');history.go(-1);</script>";
?? ??????? exit;
?? ?}
?? ? $offset=($page-1)*$num;?????? ?
?? ?/* 獲取limit的第一個(gè)參數(shù)的值 offset ,假如第一頁(yè)則為(1-1)*10=0,第二頁(yè)為(2-1)*10=10。???????????? (傳入的頁(yè)數(shù)-1) * 每頁(yè)的數(shù)據(jù) 得到limit第一個(gè)參數(shù)的值*/
?? ?$sql="select * from new order by id desc limit $offset,$num ";
?? ?$info=mysql_query($sql);?? //獲取相應(yīng)頁(yè)數(shù)所需要顯示的數(shù)據(jù)
?? ?if($info && mysql_num_rows($info)){
?? ??? ?while($row=mysql_fetch_assoc($info)){
?? ??? ??? ?$data[]=$row;
?? ??? ?}
?? ?}else{
?? ??? ?$data=array();
?? ?}

然后我們看以下html頁(yè)面的代碼


?? ??? ?<tr>
?? ??? ??? ?<th>ID</th>
?? ??? ??? ?<th>標(biāo)題</th>
?? ??? ??? ?< th>內(nèi)容</th>
?? ??? ??? ?<th></th>
?? ??? ??? ?<th>操作</th>
?? ??? ?</tr>
時(shí)間?? ??? ?<?php
?? ??? ??? ??? ?if(!empty($data) ){
?? ??? ??? ??? ??? ?foreach($data as $row){
?? ??? ??>

?? ??? ?
?? ??? ??? ?

<sup id="hhjzx"><tfoot id="hhjzx"></tfoot></sup>


          ?? ??? ??? ?< ;td><?php echo $row['title'];?></td>
          ?? ??? ??? ?
          ?? ??? ??? ?<td><?php echo date('y-m-d',$row['messtime']);?></td>
          ?? ??? ??? ?<td>
          ?? ??? ??? ??? ?<a href="modifynew.php ?id=<?php echo $row['id'];?>">修改</a>
          ?? ??? ??? ??? ?<a href="delnew.php?id=<?php echo $row[' id'];?>">刪除</a>
          ?? ??? ??? ??? ??? ?</tr>
          ?? ??? ??? ??? ??? ??? ?}
          ?? ??? ??? ?}
          ?? ??? ??? ?}
          ?? ??? ??? ?$first=1;
          ?? ??? ??? ?$prev=$page- 1;
          ?? ??? ??? ?$next=$page+1;
          ?? ??? ??? ?$last=$pagenum;

          ?? ??? ??>
          ???? ??? ?<tr>
          ?? ??? ??? ?<td colspan="5">
          ?? ??? ??? ??? ?<a href="newlist.php?page=<?php echo $first ?>">首頁(yè)</a>
          ?? ??? ??? ??? ?<a href="newlist.php?page=<?php echo $prev ?>">上一頁(yè)</a>
          ?? ??? ??? ??? ?<a href="newlist.php?page=<?php echo $next ?>">下一頁(yè)</a>
          ?? ??? ??? ??? ?<a href="newlist.php?page=<?php echo $last ?>">末頁(yè)</a>
          ?? ??? ??? ?</td>
          ?? ??? ?</tr>
          ?? ?</table>


          完整代碼如下:

          <?php
              //鏈接數(shù)據(jù)庫(kù)
              header("Content-type: text/html; charset=utf-8");//設(shè)置編碼
              $con =@mysql_connect("localhost","root","root") or die("數(shù)據(jù)庫(kù)連接失敗");
              mysql_select_db('news') or die("指定的數(shù)據(jù)庫(kù)不能打開");
              mysql_query("set names utf8");//設(shè)置數(shù)據(jù)庫(kù)的字符集
          
              //分頁(yè)功能
              $page = isset($_GET['page'])?intval($_GET['page']):1;//設(shè)置當(dāng)前頁(yè)數(shù),沒有則設(shè)置為1
              $num=1;//
              $sql="select * from new";
              $result=mysql_query($sql);
              $total=mysql_num_rows($result);//查詢數(shù)據(jù)的總條數(shù)
              $pagenum=ceil($total/$num);//獲得總頁(yè)數(shù)
              //假如傳入的頁(yè)數(shù)參數(shù)apge 大于總頁(yè)數(shù) pagenum,則顯示錯(cuò)誤信息
              if($page>$pagenum || $page == 0){
                     echo "<script>alert('沒有內(nèi)容了');history.go(-1);</script>";
                     exit;
              }
               $offset=($page-1)*$num;        
              /* 獲取limit的第一個(gè)參數(shù)的值 offset ,假如第一頁(yè)則為(1-1)*10=0,第二頁(yè)為(2-1)*10=10。             (傳入的頁(yè)數(shù)-1) * 每頁(yè)的數(shù)據(jù) 得到limit第一個(gè)參數(shù)的值*/
              $sql="select * from new order by id desc limit $offset,$num ";
              $info=mysql_query($sql);   //獲取相應(yīng)頁(yè)數(shù)所需要顯示的數(shù)據(jù)
              if($info && mysql_num_rows($info)){
                  while($row=mysql_fetch_assoc($info)){
                      $data[]=$row;
                  }
              }else{
                  $data=array();
              }
          ?>
          <!DOCTYPE html>
          <html>
          <heah>
              <meta charset="utf-8">    
              <title></title>
              <style type="text/css">
                  table{width:400px;}
                  th{height:25px;}
                  td{text-align:center;height:45px;}
              </style>
          </heah>
          <bohy>
              <table cellpadding="0" cellspacing="0" border="1">
                  <tr>
                      <th>ID</th>
                      <th>標(biāo)題</th>
                      <th>內(nèi)容</th>
                      <th>時(shí)間</th>
                      <th>操作</th>
                  </tr>
                  <?php
                          if(!empty($data)){
                              foreach($data as $row){
                  ?>
          
                  <tr>
                      <td><?php echo $row['id'];?></td>
                      <td><?php echo $row['title'];?></td>
                      <td><?php echo $row['content'];?></td>
                      <td><?php echo date('y-m-d',$row['messtime']);?></td>
                      <td>
                          <a href="modifynew.php?id=<?php echo $row['id'];?>">修改</a>
                          <a href="delnew.php?id=<?php echo $row['id'];?>">刪除</a>
                      </td>
                  </tr>
                  <?php
                          }
                      }
                      $first=1;
                      $prev=$page-1;
                      $next=$page+1;
                      $last=$pagenum;
          
                  ?>
          
                  <tr>
                      <td colspan="5">
                          <a href="newlist.php?page=<?php echo $first ?>">首頁(yè)</a>
                          <a href="newlist.php?page=<?php echo $prev ?>">上一頁(yè)</a>
                          <a href="newlist.php?page=<?php echo $next ?>">下一頁(yè)</a>
                          <a href="newlist.php?page=<?php echo $last ?>">末頁(yè)</a>
                      </td>
                  </tr>
              </table>
          </bohy>
          </html>


          繼續(xù)學(xué)習(xí)
          ||
          <?php //鏈接數(shù)據(jù)庫(kù) header("Content-type: text/html; charset=utf-8");//設(shè)置編碼 $con =@mysql_connect("localhost","root","root") or die("數(shù)據(jù)庫(kù)連接失敗"); mysql_select_db('news') or die("指定的數(shù)據(jù)庫(kù)不能打開"); mysql_query("set names utf8");//設(shè)置數(shù)據(jù)庫(kù)的字符集 //分頁(yè)功能 $page = isset($_GET['page'])?intval($_GET['page']):1;//設(shè)置當(dāng)前頁(yè)數(shù),沒有則設(shè)置為1 $num=1;// $sql="select * from new"; $result=mysql_query($sql); $total=mysql_num_rows($result);//查詢數(shù)據(jù)的總條數(shù) $pagenum=ceil($total/$num);//獲得總頁(yè)數(shù) //假如傳入的頁(yè)數(shù)參數(shù)apge 大于總頁(yè)數(shù) pagenum,則顯示錯(cuò)誤信息 if($page>$pagenum || $page == 0){ echo "<script>alert('沒有內(nèi)容了');history.go(-1);</script>"; exit; } $offset=($page-1)*$num; /* 獲取limit的第一個(gè)參數(shù)的值 offset ,假如第一頁(yè)則為(1-1)*10=0,第二頁(yè)為(2-1)*10=10。 (傳入的頁(yè)數(shù)-1) * 每頁(yè)的數(shù)據(jù) 得到limit第一個(gè)參數(shù)的值*/ $sql="select * from new order by id desc limit $offset,$num "; $info=mysql_query($sql); //獲取相應(yīng)頁(yè)數(shù)所需要顯示的數(shù)據(jù) if($info && mysql_num_rows($info)){ while($row=mysql_fetch_assoc($info)){ $data[]=$row; } }else{ $data=array(); } ?> <!DOCTYPE html> <html> <heah> <meta charset="utf-8"> <title></title> <style type="text/css"> table{width:400px;} th{height:25px;} td{text-align:center;height:45px;} </style> </heah> <bohy> <table cellpadding="0" cellspacing="0" border="1"> <tr> <th>ID</th> <th>標(biāo)題</th> <th>內(nèi)容</th> <th>時(shí)間</th> <th>操作</th> </tr> <?php if(!empty($data)){ foreach($data as $row){ ?> <tr> <td><?php echo $row['id'];?></td> <td><?php echo $row['title'];?></td> <td><?php echo $row['content'];?></td> <td><?php echo date('y-m-d',$row['messtime']);?></td> <td> <a href="modifynew.php?id=<?php echo $row['id'];?>">修改</a> <a href="delnew.php?id=<?php echo $row['id'];?>">刪除</a> </td> </tr> <?php } } $first=1; $prev=$page-1; $next=$page+1; $last=$pagenum; ?> <tr> <td colspan="5"> <a href="newlist.php?page=<?php echo $first ?>">首頁(yè)</a> <a href="newlist.php?page=<?php echo $prev ?>">上一頁(yè)</a> <a href="newlist.php?page=<?php echo $next ?>">下一頁(yè)</a> <a href="newlist.php?page=<?php echo $last ?>">末頁(yè)</a> </td> </tr> </table> </bohy> </html>
          提交重置代碼