:::

4-2 index.php

01<?php
02 
03  require_once "function.php";
04 
05  //列出所有內容
06  $news_list=list_news();
07 
08  //套用樣板並顯示頁面
09  show_page('list_tpl');
10 
11 
12 
13 
14  //列出所有內容
15  function list_news(){
16 
17    link_db();
18 
19    //讀取eznews資料表所有欄位(日期大到小排列)
20    $sql="select * from eznews order by post_time desc";
21 
22    //傳回值存到 $result 以供抓取資料用
23    $result=mysql_query($sql) or die("{$sql}<br>".mysql_error());
24 
25    $news_list="
26    <table class='table table-striped table-bordered'>
27    <tr>
28      <th class='col-md-7 text-center'>新聞標題</th>
29      <th class='col-md-3 text-center'>發布時間</th>
30      <th class='col-md-2 text-center'>功能</th>
31    </tr>
32 
33    ";
34    //取回資料庫一筆資料,並以欄位名稱為索引的資料陣列
35    while($news=mysql_fetch_assoc($result)){
36 
37      $title=empty($news['news_title'])?"無標題":$news['news_title'];
38 
39      $news_list.="
40      <tr>
41        <td>
42          <a href='{$_SERVER['PHP_SELF']}?op=view&sn={$news['sn']}'>{$title}</a>
43        </td>
44        <td class='text-center'>{$news['post_time']}</td>
45        <td class='text-center'>
46          <a href='#' class='btn btn-xs btn-danger'>刪除</a>
47          <a href='#' class='btn btn-xs btn-warning'>編輯</a>
48        </td>
49      </tr>
50      ";
51      //$news_list=$news_list."<li>{$news['news_title']}</li>";
52    }
53    $news_list.="</table>";
54 
55    return $news_list;
56  }
57 
58?>

 


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.cp27.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1051%26tbsn%3D34

書籍目錄

展開 | 闔起

線上使用者

49人線上 (14人在瀏覽線上書籍)

會員: 0

訪客: 49

更多…