Home > Backend Development > PHP Tutorial > php文章列表分页代码如何写

php文章列表分页代码如何写

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:08:03
Original
1047 people have browsed it

php文章列表分页代码怎么写?

$sql = "SELECT * FROM `links` WHERE `subdomain` != '' ORDER BY id desc LIMIT 100";<br />$rows = $db->getData($sql);<br />foreach($rows as $row)<br />{<br />	echo '<li><a href="http://'.$row['subdomain'].'.abc.com/" title="'.$row['title'].'">'.$row['title'].'</a></li>';<br />}<br />
Copy after login

第一页的文章调用我会写,但是要分页不知道怎么写
现在有字段 title subdomain
------解决思路----------------------
直接找个分页函数应用就可以了。
大约参数如下:
1 总数
2 当前页
3 每页数量
4 baseUrl,你所说的title及subdomain都以GET方式传送。
5 显示页面数量
<br />class CCustomWidgets {<br />  public static function Pager($totalPages, $pageNumber, $pageSize, $url, $displayNumber = 6) {<br />    $baseUrl = (strpos($url, "?") === false) ? $url.'?page=' : $url.'&page=';<br />    $pager = '<div class="pager"><ul>';<br /><br />    $prevPage = $pageNumber - 1;<br />    if($prevPage > 0){<br />      $pager .= '<li><a href="'.$baseUrl. $prevPage.'"><span class="pager-previous">??????é??</span></a></li>';<br />    }<br /><br />    if($totalPages - $pageNumber < $displayNumber) {<br />      $displayStart = ($totalPages >= $displayNumber) ? ($totalPages - $displayNumber + 1) : 1;<br />      $displayEnd = $totalPages;<br />    }else{<br />      if($pageNumber % $displayNumber){<br />        $displayStart = floor($pageNumber  / $displayNumber) * $displayNumber + 1;<br />        $displayEnd = (floor($pageNumber  / $displayNumber) + 1) * $displayNumber;<br />      }else{<br />        $displayStart = (floor(($pageNumber / $displayNumber) - 1)) * $displayNumber + 1;<br />        $displayEnd = (floor($pageNumber / $displayNumber)) * $displayNumber;<br />      }<br />    }<br /><br /><br />    for(; $displayStart <= $displayEnd; $displayStart++) {<br />      $pager .= '<li><a href="'.$baseUrl.$displayStart.'"><span '.(($pageNumber == $displayStart) ? 'class="active"' : '').'>'.$displayStart.'</span></a></li>';<br />    }<br />    if($pageNumber < $totalPages){<br />      $pager .= '<li><a href="'.$baseUrl. ($pageNumber + 1) .'"><span class="pager-next">??????é??</span></a></li>';<br />    }<br />    $pager .= "</ul></div>";<br />    return $pager;<br />  }<br />}<br /><br />
Copy after login


------解决思路----------------------
如果你的分页要在数据库上做的话 这两个字段不够啊,你只有标题和文章的一部分。 你至少还要标识出这个domain是文章的第几段/页 还有就是标识文章的id 标题是能够重复的

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template