線上書籍

Home

[1032]PHP入門

<?php require_once "function.php"; //列出所有內容 $news_list=list_news(); //套用樣板並顯示頁面 show_page('list_tpl'); //列出所有內容 function list_news(){ link_db(); //讀取eznews資料表所有欄位(日期大到小排列) $sql="select * from eznews order by post_time desc"; //傳回值存到 $result 以供抓取資料用 $result=mysql_query($sql) or die("{$sql}<br>".mysql_error()); $news_list=" <table class='table table-striped table-bordered'> <tr> <th class='col-md-7 text-center'>新聞標題</th> <th class='col-md-3 text-center'>發布時間</th> <th class='col-md-2 text-center'>功能</th> </tr> "; //取回資料庫一筆資料,並以欄位名稱為索引的資料陣列 while($news=mysql_fetch_assoc($result)){ $title=empty($news['news_title'])?"無標題":$news['news_title']; $news_list.=" <tr> <td> <a href='{$_SERVER['PHP_SELF']}?op=view&sn={$news['sn']}'>{$title}</a> </td> <td class='text-center'>{$news['post_time']}</td> <td class='text-center'> <a href='#' class='btn btn-xs btn-danger'>刪除</a> <a href='#' class='btn btn-xs btn-warning'>編輯</a> </td> </tr> "; //$news_list=$news_list."<li>{$news['news_title']}</li>"; } $news_list.="</table>"; return $news_list; } ?>