Jump to content

Archived

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

foreverhex

Pagination issue... [solved]

Recommended Posts

I have just started learning pagination. And I looked up this tutorial on here [url=http://www.phpfreaks.com/tutorials/43/0.php]http://www.phpfreaks.com/tutorials/43/0.php[/url]. 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:

[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>';

?> [/code]

Share this post


Link to post
Share on other sites
Look at this block of code:

[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;
    }[/code]

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.

Share this post


Link to post
Share on other sites

×

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.