Jump to content

[SOLVED] Pagination + extra pages


supanoob

Recommended Posts

I have the following code for my pagination (taken from the tut on this site) and it is adding an extra page and sometimes like 4 extra pages, it seems to be make twice as many pages as is needed. Can you see why?

 

<?php

$page=$_GET['page'];
//connect to the database
$dbh=mysql_connect ("localhost", "porky", "yellow22") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("game");
//end db connect


    $limit          = 10;               
    $query_count    = "SELECT todo_done FROM todo";    
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_num_rows($result_count); 

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

    $limitvalue = (($page*$limit)-$limit); 
    $query  = "SELECT * FROM todo where todo_done='1' ORDER BY todo_id desc LIMIT $limitvalue, $limit";        
    $result = mysql_query($query) or die("Error: " . mysql_error()); 

    if(mysql_num_rows($result) == 0){
        echo("");
    }

echo "<table border=\"0\" width=\"100%\" id=\"table1\" cellspacing=\"1\" cellpadding=\"0\">

  <tr>
	<td width=\"19%\"><b>Title</b></td>
	<td width=\"12%\"><b>Percent Done</b></td>
	<td width=\"10%\"><b>Start</b></td>
	<td width=\"16%\"><b>Days To Complete</b></td>
	<td width=\"15%\"><b>Update Type</b></td>
	<td width=\"8%\"><b>Urgency</b></td></tr>";
     
while($row = mysql_fetch_array($result)){
$todo_title=($row['todo_title']);
$todo_percent=($row['todo_percent']);
$todo_eta=($row['todo_eta']);
$todo_type=($row['todo_type']);
$todo_urgency=($row['todo_urgency']);
$todo_description=($row['todo_description']);
$todo_id=($row['todo_id']);
$start_date=($row['start_date']);

echo "<tr>                    
	<td bgcolor=\"#333333\">$todo_title</td>
	<td bgcolor=\"#333333\">$todo_percent%</td>
	<td bgcolor=\"#333333\">$start_date</td>
	<td bgcolor=\"#333333\">$todo_eta Days</td>
	<td bgcolor=\"#333333\">$todo_type</td>
	<td bgcolor=\"#333333\">";
	if ($todo_urgency == 'Low'){echo "<font color=green>";}
	if ($todo_urgency == 'Medium'){echo "<font color=orange>";}
	if ($todo_urgency == 'High'){echo "<font color=red>";}
    echo "$todo_urgency";
    if ($todo_urgency == 'Low'){echo "</font>";}
	if ($todo_urgency == 'Medium'){echo "</font>";}
	if ($todo_urgency == 'High'){echo "</font>";}
    echo "</td>
    </tr>
<tr>
	<td width=\"10%\" bgcolor=\"#666666\"><b>Update Description:</b></td>
	<td colspan=\"4\" width=\"100%\" bgcolor=\"#666666\">$todo_description</td>
</tr>";
}

echo "</table></center>";

echo "<center>";
if($page != 1){ 
        $pageprev = ($page-1);
        
        echo("<a href=\"todo.php?step=view_done&page=$pageprev\"><</a> "); 
    }else{
        echo("< ");
    }

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


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

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = ($page+1);
         
        echo("<a href=\"todo.php?step=view_done&page=$pagenext\">></a>"); 
    }else{
        echo(">"); 
    }
    
    mysql_free_result($result); 
echo "</center>";

?>

Link to comment
https://forums.phpfreaks.com/topic/56936-solved-pagination-extra-pages/
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.