Jump to content

Pagination Problem


lansing

Recommended Posts

I have read the Pagination tutorials here & chose to use the [b][i]Pagination: Easy as PREV 1 2 3 NEXT[/i][/b] 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.

[code]<?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);

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/7419-pagination-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.