Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/14542-pagination-issue-solved/
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.