Paginatating PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Why is this code that I have written to paginate the result from database
jumping to else condition where the NEXT or PREVIOUS is not hyperlinked as
in the if condition. There is enough data to display this result and to
paginate but its simply showing the else condition which does not have NEXT
or PREVIOUS hyperlinked.

--------------------- CODE -------------------------


   $host = 'xxx';      
   $user = 'xxx';
   $password = 'xxx';
   $database = 'xxx';
      
    @mysql_connect($host, $user, $password) or die("ERROR--CAN'T CONNECT TO
SERVER");
    @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");

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

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

    $limitvalue = $page * $limit - ($limit); 
    $query  = "SELECT * FROM students 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.">&nbsp;<td>");
    echo($row["name"]);
    echo("</td>n<td>");
    echo($row["major"]);
    echo("</td>n</tr>");
    }

    echo("</table>");

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

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


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo(" \"$PHP_SELF?page=$i\" $i  ");
        }
   
-- 
View this message in context: http://www.nabble.com/Paginatating-PHP-tf2861083.html#a7994164
Sent from the Php - Database mailing list archive at Nabble.com.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux