Jump to content

pagination problem?


shams

Recommended Posts

hi,
since days i want to try pagination of mysql query from a hospital database but no success i tried many codes from the web,  this  is a code but the links are not working or say there is no links there is just a printed text in the links:

<?php
// Make a MySQL Connection
// Connects to your Database
include 'library/config.php';
include 'library/opendb.php';

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

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

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM pharmacy 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>");
    echo ("<tr><th>Id</th><th>Code</th></tr>");
   
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor."><td>");
    echo($row["id"]);
    echo("</td><td>");
    echo($row["Code"]);
    echo("</td></tr>");
    }

    echo("</table>");

    if($page != 1){
        $pageprev = $page--;
       
        echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ");
    }else{
        echo("PREV".$limit." ");
    }

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


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

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

?>
this the ouput in simple text with on links to click:
Id Code
1 23uy
2 gz78
PREV2 1 NEXT2
Link to comment
https://forums.phpfreaks.com/topic/29190-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.