Jump to content

actual pagination problem


er0x

Recommended Posts

i have the script set up to show 10 results per page... shows the 10 fine... just doesnt show the links to go to the other pages of links. so i can only see the first 10.

 

LINK TO SCRIPT -http://er0x.byethost6.com/?page=links

 

i would like it to work with the ?page=links url... like ?page=links&page=1 or something like that...

so heres my code. please help...

 

<font size="2" color="008aff"><a href="?page=links/submit">Add a link</a><br /><br />

 

 

 

 

 

<?php

 

    $host = "sql1.byethost6.com";

    $username = "xxxxxxxx";

    $password = "xxxxxxxx";

    $db = "xxxxxxxx";

    mysql_connect($host,$username,$password) or die ("error");

    mysql_select_db($db) or die("error");

 

 

    $limit          = 10;             

    $query_count    = "SELECT count(*) FROM links";   

    $result_count  = mysql_query($query_count);   

    $totalrows      = mysql_num_rows($result_count);

 

    if(empty($page)){

        $page = 1;

    }

       

 

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

    $query  = "SELECT * FROM links LIMIT $limitvalue, $limit";       

    $result = mysql_query($query) or die("Error: " . mysql_error());

 

    if(mysql_num_rows($result) == 0){

        echo("Nothing to Display!");

    }

$color = array("#353535","#3a3a3a");

$tcolor = #008aff

$num_colors = count($color)-1;

$i = 0;

echo "<table>";

while($row = mysql_fetch_array($result)){

//Resets the color counter to 0 if it gets too high

    if($i > $num_colors){$i = 0;}

    echo "<tr bgcolor=\"".$color[$i]."\">";

    echo "  <td width=\"375\"><a href=\"".$row['link']."\"  target=\"_blank\">".$row["linkname"]."</a> <font color=\"008AFF\"> - ".$row["description"]."</td></tr>";

 

$i++;

}

echo "</table>";

 

    if($page != 1){

        $pageprev = $page--;

       

        echo"<a href=\"?page=links&page=$pageprev\">PREV".$limit."</a> ";

    }else{

        echo("PREV".$limit." ");

    }

 

    $numofpages = $totalrows / $limit;

   

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

        if($i == $page){

            echo($i." ");

        }else{

            echo"<a href=\"?page=links&page=$i\">$i</a> ";

        }

    }

 

 

    if(($totalrows % $limit) != 0){

        if($i == $page){

            echo($i." ");

        }else{

            echo"<a href=\"?page=links&page=$i\">$i</a> ";

        }

    }

 

    if(($totalrows - ($limit * $page)) > 0){

        $pagenext = $page++;

       

        echo"<a href=\"?page=links&page=$pagenext\">NEXT".$limit."</a>";

    }else{

        echo("NEXT".$limit);

    }

   

    mysql_free_result($result);

 

?></font>

 

Link to comment
https://forums.phpfreaks.com/topic/68938-actual-pagination-problem/
Share on other sites

alright I see a very early problem

<?php

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

In this bit I'm assuming you are trying to get the page number from the url so you need to include $page = $_GET['page'] and also you should run it like this

 

<?php
$page = $_GET['page'];
    if(empty($page) || !is_numeric($page)){
        $page = 1;
    }
?>

 

That being said you need your url to be structured like

http://er0x.byethost6.com/?page=links&page=1 as you said.

 

now lets look at the rest.  You are querying for the total number of pages already just don't use that * operator, instead use the primary key of the table since it will save you a lot of resources. The error i'm seeing is in your echoing of the links try this

instead of your current link echoing

 

<?php
        echo"<a href=\"".$_SERVER['self']."?page=links&page=$pagenext\">NEXT".$limit."</a>"; 
?>

 

Otherwise I'm going to say that you need to make sure your outputted values for the number of results/rows/pages make sense, by simply echoing them out after they are established to verify their values.

ok well, i have changed the code to with what u said.. they still arent showing up as links. but i was playing around with it and discovered that

 

                echo"<a href=\"".$_SERVER['self']."?page=links&page=$pagenext\">NEXT</a>"; 
    }else{
        echo"<a href=\"".$_SERVER['self']."&page=$pagenext\">NEXT".$limit."</a>"; 

will display it as a link but the page it links to doesnt work... goes to http://www.er0x.byethost6.com/?page=links&page=  but no page number.

 

regular code is...

 

        echo"<a href=\"?page=links&page=$pagenext\">NEXT".$limit."[/url]";
    }else{
        echo("NEXT".$limit); // this is the line it is displaying (linkless)

<?php
                echo"<a href=\"".$_SERVER['self']."?page=links&page=$pagenext\">NEXT</a>"; 
    }else{
        echo"<a href=\"".$_SERVER['self']."&page=$pagenext\">NEXT".$limit."</a>"; 
?>

try this instead

<?php
                echo"<a href=\"".$_SERVER['self']."?page=links&page=".$pagenext."\">NEXT</a>"; 
    }else{
        echo"<a href=\"".$_SERVER['self']."?page=."$pagenext."\">NEXT".$limit."</a>"; 

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.