How to write the paging code of the php article list? $ SQL & nbsp ;=& nbsp; "SELECT & nbsp; * & nbsp; FROM & nbsp; 'link' & nbsp; WHERE & nbsp; 'subdomain '& nbsp ;! = & Nbsp; ''& nbsp; ORDER & nbsp; BY & nb php article list paging code how to write?
$sql = "SELECT * FROM `links` WHERE `subdomain` != '' ORDER BY id desc LIMIT 100";
$rows = $db->getData($sql);
foreach($rows as $row)
{
echo '
'.$row['title'].'';
}
I will write the article on the first page, but I don't know how to write it if I need to paging it.
Currently, the title subdomain field is available.
------ Solution --------------------
You can directly find a paging function application.
The approximate parameters are as follows:
1 Total
2 Current page
3 page size
4. baseUrl. The title and subdomain you mentioned are all transmitted in GET mode.
5. display page quantity
class CCustomWidgets {
public static function Pager($totalPages, $pageNumber, $pageSize, $url, $displayNumber = 6) {
$baseUrl = (strpos($url, "?") === false) ? $url.'?page=' : $url.'&page=';
$pager = '
';
$prevPage = $pageNumber - 1;
if($prevPage > 0){
$pager .= '
- ??????é??
';
}
if($totalPages - $pageNumber < $displayNumber) {
$displayStart = ($totalPages >= $displayNumber) ? ($totalPages - $displayNumber + 1) : 1;
$displayEnd = $totalPages;
}else{
if($pageNumber % $displayNumber){
$displayStart = floor($pageNumber / $displayNumber) * $displayNumber + 1;
$displayEnd = (floor($pageNumber / $displayNumber) + 1) * $displayNumber;
}else{
$displayStart = (floor(($pageNumber / $displayNumber) - 1)) * $displayNumber + 1;
$displayEnd = (floor($pageNumber / $displayNumber)) * $displayNumber;
}
}
for(; $displayStart <= $displayEnd; $displayStart++) {
$pager .= '
- '.$displayStart.'
';
}
if($pageNumber < $totalPages){
$pager .= '
- ??????é??
';
}
$pager .= "
";
return $pager;
}
}
------ Solution --------------------
These two fields are not enough if your paging is to be performed on the database. you only have part of the title and article. You must at least identify the domain as the segment/page of the article, and the id and title of the document can be repeated.