开发者

pagination fixing php mysql

开发者 https://www.devze.com 2023-03-14 01:23 出处:网络
this pagination only for next and previous wallpaper/ query, but its show also empty rows, how to fix it?

this pagination only for next and previous wallpaper/ query , but its show also empty rows, how to fix it?

<?php 

// Figure out 开发者_JAVA技巧the limit for the query based 
// on the current page number. 
$from = (($walpaperid * $max_results) - $max_results);  

// Figure out the total number of results in DB: 
$total_results = mysql_result(mysql_query("SELECT COUNT( * ) AS `Rows` , `wallpaperid` 
                 FROM `wallpaper` ORDER BY `wallpaper`.`wallpaperid` ASC"),0) or die(mysql_error()); 

// Figure out the total number of pages. Always round up using ceil() 
$total_pages = ceil($from / $max_results); 

// Build Page Number Hyperlinks 

// Build Previous Link 
if($wallpaperid > 1){ 
    $prev = ($wallpaperid - 1); 
        echo "<a href=\"edit-delete-wallpaper.php?wallpaperid=$prev\">&lt;Previous Page</a>&nbsp;";  
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($pagenum) == $i){ 
        echo "<strong>$i</strong> "; 
    } else { 
            echo "<a class = 'mlnk' href=\"$siteurl3/$cat_url-$catid-$i.php\">$i</a> |";

    } 
} 

// Build Next Link 
if($wallpaperid < $total_pages){ 
    $next = ($wallpaperid + 1); 

     echo "<a href=\"edit-delete-wallpaper.php?wallpaperid=$next\">Next Page&gt;</a>"; 
} 

?>


Correct your code to figure out the number of pages:

$total_pages = ceil($total_results / $max_results); 
0

精彩评论

暂无评论...
验证码 换一张
取 消