分页修复php mysql

时间:2011-06-20 20:21:02

标签: php mysql pagination

此分页仅适用于下一个和上一个壁纸/查询,但其显示也是空行, 如何解决?

<?php 

// Figure out 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>"; 
} 

?>

1 个答案:

答案 0 :(得分:0)

更正您的代码以确定页数:

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