Jump to content


Photo

Pagination Problem


  • Please log in to reply
No replies to this topic

#1 lansing

lansing
  • Members
  • PipPip
  • Member
  • 15 posts
  • LocationClinton, TN USA

Posted 14 April 2006 - 05:09 PM

I have read the Pagination tutorials here & chose to use the Pagination: Easy as PREV 1 2 3 NEXT tutorial. I have it displaying everything, but the text isn't links. I will post my code below. I don't see any code that pulls the page # from the URL in the tutorial code that I am trying to use.

<?php

    $limit          = 5;              
    $query_count    = "SELECT count(*) FROM orders";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_num_rows($result_count);

    if(empty($page)){
        $page = 1;
    }
        

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM orders LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error());

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }

    $bgcolor = "#E0E0E0"; // light gray

    echo("<table>");
    
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor.">n<td>");
    echo($row["order_id"]);
    echo("</td>n<td>");
    echo($row["customers_id"]);
    echo("</td>n</tr>");
    }

    echo("</table>");

    if($page != 1){
        $pageprev = $page--;
        
        echo("<a href=\"".$_SERVER['PHP_SELF']."?page=$pageprev\">PREV</a> ");
    }else{
        echo("PREV");
    }

    $numofpages = $totalrows / $limit;
    
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
        
        echo("<a href=\"".$_SERVER['PHP_SELF']."?page=$pagenext\">NEXT ".$limit."</a>");
    }else{
        echo("NEXT ".$limit);
    }
    
    mysql_free_result($result);

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users