国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

文章列表顯示功能

1,準(zhǔn)備資料

需要準(zhǔn)備好所有文章分類的資訊,所有文章詳情的資訊,操作資料庫進(jìn)行查詢

新index.php頁面,程式碼如下:

<?php
header("Content-Type:text/html;charset=utf-8");
//獲取要查詢的分類ID,0表示全部
$cid=isset($_GET['cid'])?intval($_GET['cid']):0;
//獲取查詢列表條件
$where='';
if($cid) $where="where cid=$cid";
//初始化數(shù)據(jù)庫操作類
require './init.php';
//載入分頁類
require './page.class.php';
//獲取當(dāng)前頁碼號
$page=isset($_GET['page'])?intval($_GET['page']):1;
//拼接查詢條件
//獲取總記錄數(shù)
$sql="select count(*) as total from cms_article $where";
$results=$db->fetchRow($sql);
$total=$results['total'];
//實例化分頁類
$Page=new Page($total,4,$page); //Page(總記錄數(shù),每頁顯示條數(shù),當(dāng)前頁)
$limit=$Page->getLimit();  //獲取分頁鏈接條件
$page_html=$Page->showPage(); //獲取分頁html鏈接
//var_dump($total);die();
//分頁獲取文章列表
$sql="select id,title,content,author,addtime,cid from cms_article $where order by addtime DESC limit $limit";
$articles=$db->fetchAll($sql);
foreach ($articles as $k=>$v){
    //mb_substr(內(nèi)容,開始位置,截取長度,字符集)
    $articles[$k]['content']=mb_substr(trim(strip_tags($v['content'])),0,150,'utf-8').'......';
}
$sql="select name from cms_category ORDER BY sort";
$categories=$db->fetchAll($sql);
//var_dump($categories);die();
require './indexHtml.php';

程式碼對分頁類別進(jìn)行了實例化並對資料庫執(zhí)行了多次查詢操作,

獲取的資料有

分頁資訊:$page_html

#所有文章分類資訊:$categories

#依照時間排序的文章詳情資訊:$articles

以上資訊備用展示在前端頁面使用

2,前端展示頁面程式碼:

#新indexHtml.php頁面

頁面展示如下:

微信圖片_20180306163519.png

遍歷標(biāo)題列分類資料:

微信圖片_20180306163851.png

#遍歷最新文章資料:

微信圖片_20180306164711.png

往資料庫多插入幾個資料分頁效果頁面展示如下:

微信圖片_20180306165346.png


繼續(xù)學(xué)習(xí)
||
<?php echo "文章詳情顯示頁面";