Jump to content


Photo

Pagination issue... [solved]


  • Please log in to reply
2 replies to this topic

#1 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 13 July 2006 - 11:51 PM

I have just started learning pagination. And I looked up this tutorial on here http://www.phpfreaks...orials/43/0.php. I altered the code a bit but the main frame is there. My question is why does the link not work for next page? I know there is an else statement that says if there is no next page than it isnt a link... but there should be a next page! Grr pls help. Here is my code:

<?php

$orderuser = 'signupdate';

include 'db.php';
//db connect

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

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

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

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

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

    echo '<table class=ourfamily align=left valign=top>';
    
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#110000"){
            $bgcolor = "#110000";
        }else{
            $bgcolor = "#110000";
        }

    echo '
<tr bgcolor=' . $bgcolor . '>
<td width="150">
<a href="http://www.syblings.net/user.php?id=' . $row["user"] . 
'"><img src="/images/avatar/' . $row["user"] . '.jpg" width="150" border=0></a>
</td>
<td valign=top>';
    echo('<b>' . $row["user"] . '</b>');
    echo '<br /><br />';
    echo('<b>Medium(s):</b> ' . $row["medium"]);
    echo '<br />';
    echo('<b>Location:</b> ' . $row["location"]);
    echo '<br />';
    echo('<b>Interests:</b> ' . $row["interests"]);
    echo '</td></tr>
<tr>
<td colspan=2><hr width=90% color=#330000 align=center></td>
</tr>
';
    }

    echo '<tr><td colspan=2 align=center>';

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

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


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

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
        echo '&nbsp;&nbsp;&nbsp;<a href="ourfamily.php&page=$pagenext">NEXT" . $limit . "</a>'; 
    }else{
        echo '&nbsp;&nbsp;&nbsp;NEXT' . $limit; 
    }
    
    mysql_free_result($result);

echo '</td></tr></table>';

?>


#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 14 July 2006 - 02:18 AM

Look at this block of code:

if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
        echo '&nbsp;&nbsp;&nbsp;<a href="ourfamily.php&page=$pagenext">NEXT" . $limit . "</a>'; 
    }else{
        echo '&nbsp;&nbsp;&nbsp;NEXT' . $limit; 
    }

Particularly, this line:

echo '&nbsp;&nbsp;&nbsp;<a href="ourfamily.php&page=$pagenext">NEXT" . $limit . "</a>';

You are not escaping the single quotes to have the value of the variable inserted.  Change that line to be:

echo '&nbsp;&nbsp;&nbsp;<a href="ourfamily.php&page=' . $pagenext . '">NEXT ' . $limit . '</a>';

And, looking again at your code, you are doing it with the similar blocks of code above that.  Make sure you change all fo them so that you are not trying to insert a variable while it is inside of the single quotes.

Remember, single quotes means php will print EXACTLY what is there, double quotes it will substitute variable values for the variable.

#3 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 14 July 2006 - 03:35 AM

LOL. Well that was all it was. thx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users