Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pagination

Status
Not open for further replies.

calv1n

Programmer
Sep 29, 2007
18
CA
I'm trying pagination. It works fine, except the 'unhyperlinked' page numbers are 'unhyperlinked' one off.

To see what I mean click here.

I can't seem to fix it. Here is my code:

Code:
 $result = mysql_query("SELECT * FROM test");
        $total_entries = mysql_num_rows($result);
        echo "<p><br>";

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

        $limitvalue = $page * $maxentriestodisplayperpage - ($maxentriestodisplayperpage);

        echo "<table class=\"main\" width=\"$tablewidth%\" border=\"0\"><tr><td></td><td align=\"right\">";

        if($page != 1){
        $pageprev = $page--;

        echo("<a href=\"index.php?page=$pageprev\"></a> ");
    }else
        echo(" ");

        $numofpages = $total_entries / $maxentriestodisplayperpage;

    for($i = 1; $i <= $numofpages; $i++){

        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"index.php?page=$i\">$i</a> ");
        }

    }

if(($total_entries % $maxentriestodisplayperpage) != 0){

        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href=\"index.php?page=$i\">$i</a> ");
        }

    }

    if(($total_entries - ($maxentriestodisplayperpage * $page)) > 0){

        $pagenext   = $page++;

        echo("<a href=\"index.php?page=$pagenext\"></a>");
    }else{
        echo("");
    }

    mysql_free_result($result);

Thank you.

-CALV1N
 
Hi, I would recreate this entire script, as it's very unsafe and it has logical errors which can lead to abuse / sql injection.

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top