Jump to content

Results on Multiple Pages Help


tei

Recommended Posts

I've read through a few examples of how to paginate query results, but with my currently php skills I don't understand them, or they do not fit into my code.  I wondered if I could make my own, and the logic behind this code makes sense to me, but it's still not working.  Here is the code:

 

<?php

if (!$Start) {
$Start = 0;
}
else {
     $Start=$_POST['Start'];
}

$crittercount = 120;

$numpages = $crittercount / 30;
$pagei = 1;
$pagereit = 1;

echo '<p><center>
<FORM method=POST action=testpagination.php>
<SELECT NAME="Start">
        <OPTION>Page 1';
        while ($pagereit < $numpages) {
        $pagei = $pagei + 30;
        echo '<OPTION value='.$pagei.'>';
        $pagereit = $pagereit + 1;
        echo "Page: " .$pagereit;
        }
        echo '</SELECT>';
echo'<input type=submit value=Go></FORM><p>';

echo $Start;

?>

 

The test site is here:

http://lab-lib.com/felishorns/Felishorns/websitetest/testpagination.php

 

$crittercount is a variable that changes depending on the main $query.  This query is invisible, and is used to pull a count for all the results in total.  I am modifying it with $Start to create a second query which the viewer sees.

 

$queryF = $query . " LIMIT " . $Start . ", 30";

 

The idea is that $Start changes depending on the value selected, thereby changing the query.  In this test code, I've simply echoed the $Start value of that page, to see if the code is working, and it's not changing.  What's wrong with this code?  Is it not possible to have a form lead to the same link of the page it's on?  Does the variable not become updated?

 

Thanks in advance.

Link to comment
Share on other sites

No, that query is working.  I have defined $query above that code:

$query = "SELECT * FROM critter WHERE `id` IS NOT NULL AND $queryname AND $queryowner AND $querygender AND $querybreed AND $querycolorist AND $querytype";

 

Where all those variables are working dynamically and statically (if I were to place true values in to search rather than variables).  If I were to give $Start a set value, the query works.

Link to comment
Share on other sites

oh I now read what you  are really doing. You pulling everything out of the database to put in to pieces, instead of a wwhat i think a normal pagination would do. But when you already pulled all info out you can't use LIMIT (sql) in php.

I bet you than need to split the array of results after checking num_rows. let me think about this while eating some soup ::)

-edit: the problem with pulling everything from the table is that when your table gets bigger this could be huge. and how many people will read all pages?

Link to comment
Share on other sites

Yeah, the table is already pretty big with 2000+ critters, but the most important information extracted from each search is the image of the critter, and sometimes people just want to browse through all the female images.

 

I'm sorry, but could you explain when LIMIT in query won't work?

Link to comment
Share on other sites

yeah sure, sorry had to finish my soup ::)

LIMIT is (if i am correct ) an SQL function. so what one would normally do is check how many rows there are in a table.

and than let each page individually query results for a limited range. your database will get a headache.

1 sec I'll try to fix a workable soultion for you.

 

-edit here is a workable one for you: http://php.about.com/od/phpwithmysql/ss/php_pagination.htm

 

So the general idea is

1) query database and find out how many rows there are in total (mysqli_num_rows)

2) devide that number by the total results you want per page. (use ceil() to round the numbers)

3) assign queries in a while loop with limited number of results.

   

 

But keep in mind this works the same but will not cause a time out if your table is to big.

Link to comment
Share on other sites

Here is a pagination I came up with.

 

Can see a working example here.

http://get.blogdns.com/dynaindex/paginate.php

As of right now it limits to 10 per page, never got any further with it because 10 was all I wanted.

 

Maybe can even improve on this, use some idea's from it.

 

And the code.

 

<?php
//get the url from the address bar
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER["QUERY_STRING"]))
$url .= "?".$_SERVER['QUERY_STRING'];
echo "<a href='$url'>$url</a><br />";

$posts_per_page = 10;//keep this 10 for now, I never got to doing more calculations for everything yet      

//check if the starting row variable was passed in the URL or not
if (!isset($_GET['page']) or !is_numeric($_GET['page'])) {

//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;


} else {
//get starting row value from url page bumber and convert
$temp_page=mysql_real_escape_string($_GET['page']);
$convert = $temp_page * $posts_per_page -$posts_per_page;
$startrow = (int)$convert;
}
$startrow=mysql_real_escape_string($startrow);

//conversions of start row for checking and making of pages
$prev = $startrow - 10;
$prev20 = $startrow - 20;
$prev30 = $startrow - 30;
$prev40 = $startrow - 40;
$prev50 = $startrow - 50;
$prev100 = $startrow - 100;
$prev1000 = $startrow - 1000;
$prev10000 = $startrow - 10000;
$prev100000 = $startrow - 100000;
$next = $startrow + 10;
$next20 = $startrow + 20;
$next30 = $startrow + 30;
$next40 = $startrow + 40;
$next50 = $startrow + 50;
$next100 = $startrow + 100;
$next1000 = $startrow + 1000;
$next10000 = $startrow + 10000;
$next100000 = $startrow + 100000;


if ($prev20 <= -20){
$prev20 = $prev20 / 10;
}
if ($prev30 <= -30){
$prev30 = $startrow - 30;
}
if ($prev40 <= -40){
$prev40 = $startrow - 40;
}
if ($prev50 <= -50){
$prev50 = $startrow - 50;
}
if ($prev100 <= -100){
$prev100 = $startrow - 100;
}
if ($prev1000 <= -1000){
$prev1000 = $startrow - 1000;
}
if ($prev10000 <= -10000){
$prev10000 = $startrow - 10000;
}
if ($prev100000 <= -100000){
$prev100000 = $startrow - 100000;
}
if ($prev1000000 <= -1000000){
$prev1000000 = $startrow - 1000000;
}
if ($prev10000000 <= -10000000){
$prev10000000 = $startrow - 10000000;
}
if ($prev100000000 <= -100000000){
$prev100000000 = $startrow - 100000000;
}
if ($next <= +10){
$next = $startrow + 10;
}
if ($next20 <= +20){
$next20 = $startrow + 20;
}
if ($next30 <= +30){
$next30 = $startrow + 30;
}
if ($next40 <= +40){
$next40 = $startrow + 40;
}
if ($next50 <= +50){
$next50 = $startrow + 50;
}
if ($next100 <= +100){
$next100 = $startrow + 100;
}
if ($next1000 <= +1000){
$next1000 = $startrow + 1000;
}
if ($next10000 <= +10000){
$next10000 = $startrow + 10000;
}
if ($next100000 <= +100000){
$next100000 = $startrow + 100000;
}
if ($next1000000 <= +1000000){
$next1000000 = $startrow + 1000000;
}
if ($next10000000 <= +10000000){
$next10000000 = $startrow + 10000000;
}
if ($next100000000 <= +100000000){
$next100000000 = $startrow + 100000000;
}
$deduct1pages = $prev / 10 +1;
$deduct2pages = $prev20 / 10 +1;
$deduct3pages = $prev30 / 10 +1;
$deduct4pages = $prev40 / 10 +1;
$deduct5pages = $prev50 / 10 +1;
$deduct10pages = $prev100 / 10 +1;
$deduct100pages = $prev1000 / 10 +1;
$deduct1000pages = $prev10000 / 10 +1;
$deduct10000pages = $prev100000 / 10 +1;
$deduct100000pages = $prev1000000 / 10 +1;
$deduct1000000pages = $prev10000000 / 10 +1;
$deduct10000000pages = $prev100000000 / 10 +1;
$add1pages = $next / 10 +1;
$add2pages = $next20 / 10 +1;
$add3pages = $next30 / 10 +1;
$add4pages = $next40 / 10 +1;
$add5pages = $next50 / 10 +1;
$add10pages = $next100 / 10 +1;
$add100pages = $next1000 / 10 +1;
$add1000pages = $next10000 / 10 +1;
$add10000pages = $next100000 / 10 +1;
$add100000pages = $next1000000 / 10 +1;
$add1000000pages = $next10000000 / 10 +1;
$add10000000pages = $next100000000 / 10 +1;

//get the page, if none set defaults to page 1
$nav_get = mysql_real_escape_string($_GET['page']);
if (empty($_GET['page'])) {
$nav_get = 1;
}

//the navigation url gets the actual address bar url, then hacks off the get page number value, the navigation itself then replaces the value
$navigation_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];

if (!empty($_SERVER["QUERY_STRING"])){
$navigation_url .= "?".$_SERVER['QUERY_STRING'];
}
if ($url == "./" OR $url == "./index.php"){ //you can change these to your needs
$navigation_url = "$navigation_url?&page=1";
}
$navigation_url1 = "$navigation_url";
$navigation_url = trim($navigation_url1,$nav_get);

//This is where the mysql select would go using the values of LIMIT $startrow,$posts_per_page at end of select statement

//lets just echo these to see what is changing
echo "From mysql startrow $startrow and a max $posts_per_page posts per page<br />";

//total count would be the total items from the same mysql query but not using any limits
$total_count = 345781;//lets just pick some wild number so we can use this with no queries
$total_posts = $total_count;
//using total posts, convert to pages using the last total_count number
$lastposts = $total_posts - $posts_per_page;
$nextposts = $total_posts +1;
$total_posts_pages = $total_posts / $posts_per_page;
list($int,$dec)=explode('.', $total_posts_pages);
$int_pages = $int +1;
$secondfromlast = $int_pages - 1;
$thirdfromlast = $secondfromlast - 1;
$fourthfromlast = $thirdfromlast - 1;
$fifthfromlast = $fourthfromlast - 1;
$page_numbers = $startrow / $posts_per_page;
$total_pages = $total_posts / $posts_per_page;
$page_number = $startrow / $posts_per_page + 1;

if (!$_GET['page']) {
$_GET['page'] = 1;
}

if ($page_number >= $int_pages+1) {
$_GET['page'] = $int_pages;
echo "<h2>That page number exceeded the max pages this result</h2><br />";
}
if ($_GET['page'] <= 0) {
$_GET['page'] = 1;
}
if ($page_number <= 0) {
echo "<h2>That page number was lower than the pages this result</h2><br />";
}

if ($total_posts == 0){
echo '<h2>No results found.</h2>';
}

echo "Page $page_number of $int_pages - $total_posts Results<br />";

//the page navigation hyperlinks
echo '[<a href="./index.php?page=1"><b> New Posts</b></a>]';


if ($prev >= 0){
     echo '[<a href="'.$navigation_url.''.$deduct1pages.'"><b><<- Previous.. </b></a>]';
    }

if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$add1pages.'"><b> ..Next ->></b></a>]';
    }
?>
   <br />
<?php

if ($int_pages >= 1){
     echo '[<a href="'.$navigation_url.'1"> <b> First </b></a>]';
    } else {
    echo "No Resultss Found For That Search, Please Try A Different One.";
    }
    if ($int_pages >= 2){
     echo '[<a href="'.$navigation_url.'2"> <b> 2 </b></a>]';
    }
    if ($int_pages >= 3){
     echo '[<a href="'.$navigation_url.'3"> <b> 3 </b></a>]';
    }
    if ($int_pages >= 4){
     echo '[<a href="'.$navigation_url.'4"> <b> 4 </b></a>]';
    }
    if ($int_pages >= 5){
     echo '[<a href="'.$navigation_url.'5"> <b> 5 </b></a>]';
    }
    

     if ($prev >= 0){
     echo '[<a href="'.$navigation_url.''.$deduct1pages.'">-1</a>]';
    }
    if ($prev20 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct2pages.'">-2</a>]';
    }
    if ($prev30 >= 0){    
    echo '[<a href="'.$navigation_url.''.$deduct3pages.'">-3</a>]';
    }
    if ($prev40 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct4pages.'">-4</a>]';
    }
    if ($prev50 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct5pages.'">-5</a>]';
    }
    if ($prev100 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10pages.'">-10</a>]';
    }
    if ($prev1000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct100pages.'">-100</a>]';
    }
    if ($prev10000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct1000pages.'">-1000</a>]';
    }
    if ($prev100000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10000pages.'">-10000</a>]';
    }
    if ($prev1000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct100000pages.'">-100000</a>]';
    }
    if ($prev10000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct1000000pages.'">-100000</a>]';
    }
    if ($prev100000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10000000pages.'">-1000000</a>]';
    }
    
    echo '<div align="left">';
    if ($next10000000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1000000pages.'">+1000000</a>]';
    }
    if ($next1000000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add100000pages.'">+100000</a>]';
    }
    if ($next100000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add10000pages.'">+10000</a>]';
    }
    if ($next10000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1000pages.'">+1000</a>]';
    }
    if ($next1000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add100pages.'">+100</a>]';
    }
    if ($next100 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add10pages.'">+10</a>]';
    }
    if ($next50 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add5pages.'">+5</a>]';
    }
    if ($next40 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add4pages.'">+4</a>]';
    }
    if ($next30 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add3pages.'">+3</a>]';
    }
    if ($next20 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add2pages.'">+2</a>]';
    }
    if ($next <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1pages.'">+1</a>]';
    }
    
    
    if ($int_pages >= 5){
     echo '[<a href="'.$navigation_url.''.$fifthfromlast.'"><b>Last5</b></a>]';
    }
    if ($int_pages >= 4){
     echo '[<a href="'.$navigation_url.''.$fourthfromlast.'"><b>Last4</b></a>]';
    }
    if ($int_pages >= 3){
     echo '[<a href="'.$navigation_url.''.$thirdfromlast.'"><b>Last3</b></a>]';
    }
    if ($int_pages >= 2){
     echo '[<a href="'.$navigation_url.''.$secondfromlast.'"><b>Last2</b></a>]';
    }
    if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }
echo '';     
echo '<br />';
?>
<br />
<form name="input" action="<?php echo $navigation_url; ?>" method="get">

<?php
if ($_GET['page'] == 0) {
$_GET['page'] = 1;
}
?>
Page:<input onfocus="this.value=''" size="15" type="text" name="page" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="<?php echo $_GET['page']; ?>"/>

<input type="submit" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="Get Page" />

</form>

 

Link to comment
Share on other sites

Hey sorry, but my browser was saving old views and thought i had this somewhat done.

 

New code that works.

 

<?php
//get the url from the address bar
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER["QUERY_STRING"]))
$url .= "?".$_SERVER['QUERY_STRING'];
echo "<a href='$url'>$url</a><br />";

$posts_per_page = 10;//keep this 10 for now, I never got to doing more calculations for everything yet      

//check if the starting row variable was passed in the URL or not
if (!isset($_GET['page']) or !is_numeric($_GET['page'])) {

//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;


} else {
//get starting row value from url page bumber and convert
$temp_page=mysql_real_escape_string($_GET['page']);
$convert = $temp_page * $posts_per_page -$posts_per_page;
$startrow = (int)$convert;
}
$startrow=mysql_real_escape_string($startrow);

//conversions of start row for checking and making of pages
$prev = $startrow - 10;
$prev20 = $startrow - 20;
$prev30 = $startrow - 30;
$prev40 = $startrow - 40;
$prev50 = $startrow - 50;
$prev100 = $startrow - 100;
$prev1000 = $startrow - 1000;
$prev10000 = $startrow - 10000;
$prev100000 = $startrow - 100000;
$next = $startrow + 10;
$next20 = $startrow + 20;
$next30 = $startrow + 30;
$next40 = $startrow + 40;
$next50 = $startrow + 50;
$next100 = $startrow + 100;
$next1000 = $startrow + 1000;
$next10000 = $startrow + 10000;
$next100000 = $startrow + 100000;


if ($prev20 <= -20){
$prev20 = $prev20 / 10;
}
if ($prev30 <= -30){
$prev30 = $startrow - 30;
}
if ($prev40 <= -40){
$prev40 = $startrow - 40;
}
if ($prev50 <= -50){
$prev50 = $startrow - 50;
}
if ($prev100 <= -100){
$prev100 = $startrow - 100;
}
if ($prev1000 <= -1000){
$prev1000 = $startrow - 1000;
}
if ($prev10000 <= -10000){
$prev10000 = $startrow - 10000;
}
if ($prev100000 <= -100000){
$prev100000 = $startrow - 100000;
}
if ($prev1000000 <= -1000000){
$prev1000000 = $startrow - 1000000;
}
if ($prev10000000 <= -10000000){
$prev10000000 = $startrow - 10000000;
}
if ($prev100000000 <= -100000000){
$prev100000000 = $startrow - 100000000;
}
if ($next <= +10){
$next = $startrow + 10;
}
if ($next20 <= +20){
$next20 = $startrow + 20;
}
if ($next30 <= +30){
$next30 = $startrow + 30;
}
if ($next40 <= +40){
$next40 = $startrow + 40;
}
if ($next50 <= +50){
$next50 = $startrow + 50;
}
if ($next100 <= +100){
$next100 = $startrow + 100;
}
if ($next1000 <= +1000){
$next1000 = $startrow + 1000;
}
if ($next10000 <= +10000){
$next10000 = $startrow + 10000;
}
if ($next100000 <= +100000){
$next100000 = $startrow + 100000;
}
if ($next1000000 <= +1000000){
$next1000000 = $startrow + 1000000;
}
if ($next10000000 <= +10000000){
$next10000000 = $startrow + 10000000;
}
if ($next100000000 <= +100000000){
$next100000000 = $startrow + 100000000;
}
$deduct1pages = $prev / 10 +1;
$deduct2pages = $prev20 / 10 +1;
$deduct3pages = $prev30 / 10 +1;
$deduct4pages = $prev40 / 10 +1;
$deduct5pages = $prev50 / 10 +1;
$deduct10pages = $prev100 / 10 +1;
$deduct100pages = $prev1000 / 10 +1;
$deduct1000pages = $prev10000 / 10 +1;
$deduct10000pages = $prev100000 / 10 +1;
$deduct100000pages = $prev1000000 / 10 +1;
$deduct1000000pages = $prev10000000 / 10 +1;
$deduct10000000pages = $prev100000000 / 10 +1;
$add1pages = $next / 10 +1;
$add2pages = $next20 / 10 +1;
$add3pages = $next30 / 10 +1;
$add4pages = $next40 / 10 +1;
$add5pages = $next50 / 10 +1;
$add10pages = $next100 / 10 +1;
$add100pages = $next1000 / 10 +1;
$add1000pages = $next10000 / 10 +1;
$add10000pages = $next100000 / 10 +1;
$add100000pages = $next1000000 / 10 +1;
$add1000000pages = $next10000000 / 10 +1;
$add10000000pages = $next100000000 / 10 +1;

//get the page, if none set defaults to page 1
$nav_get = mysql_real_escape_string($_GET['page']);
if (empty($_GET['page'])) {
$nav_get = 1;
}

//the navigation url gets the actual address bar url, then hacks off the get page number value, the navigation itself then replaces the value
$navigation_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];

if (!empty($_SERVER["QUERY_STRING"])){
$navigation_url .= "?".$_SERVER['QUERY_STRING'];
}
if ($url == "./" OR $url == "./index.php"){ //you can change these to your needs
$navigation_url = "$navigation_url?&page=1";
}
$navigation_url = trim($navigation_url1,$nav_get);
$navigation_url ="$navigation_url?page=";
//This is where the mysql select would go using the values of LIMIT $startrow,$posts_per_page at end of select statement

//lets just echo these to see what is changing
echo "From mysql startrow $startrow and a max $posts_per_page posts per page<br />";

//total count would be the total items from the same mysql query but not using any limits
$total_count = 345781;//lets just pick some wild number so we can use this with no queries
$total_posts = $total_count;
//using total posts, convert to pages using the last total_count number
$lastposts = $total_posts - $posts_per_page;
$nextposts = $total_posts +1;
$total_posts_pages = $total_posts / $posts_per_page;
list($int,$dec)=explode('.', $total_posts_pages);
$int_pages = $int +1;
$secondfromlast = $int_pages - 1;
$thirdfromlast = $secondfromlast - 1;
$fourthfromlast = $thirdfromlast - 1;
$fifthfromlast = $fourthfromlast - 1;
$page_numbers = $startrow / $posts_per_page;
$total_pages = $total_posts / $posts_per_page;
$page_number = $startrow / $posts_per_page + 1;

if (!$_GET['page']) {
$_GET['page'] = 1;
}

if ($page_number >= $int_pages+1) {
$_GET['page'] = $int_pages;
echo "<h2>That page number exceeded the max pages this result</h2><br />";
}
if ($_GET['page'] <= 0) {
$_GET['page'] = 1;
}
if ($page_number <= 0) {
echo "<h2>That page number was lower than the pages this result</h2><br />";
}

if ($total_posts == 0){
echo '<h2>No results found.</h2>';
}

echo "Page $page_number of $int_pages - $total_posts Results<br />";

//the page navigation hyperlinks
echo '[<a href="./index.php?page=1"><b> New Posts</b></a>]';


if ($prev >= 0){
     echo '[<a href="'.$navigation_url.''.$deduct1pages.'"><b><<- Previous.. </b></a>]';
    }

if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$add1pages.'"><b> ..Next ->></b></a>]';
    }
?>
   <br />
<?php

if ($int_pages >= 1){
     echo '[<a href="'.$navigation_url.'1"> <b> First </b></a>]';
    } else {
    echo "No Resultss Found For That Search, Please Try A Different One.";
    }
    if ($int_pages >= 2){
     echo '[<a href="'.$navigation_url.'2"> <b> 2 </b></a>]';
    }
    if ($int_pages >= 3){
     echo '[<a href="'.$navigation_url.'3"> <b> 3 </b></a>]';
    }
    if ($int_pages >= 4){
     echo '[<a href="'.$navigation_url.'4"> <b> 4 </b></a>]';
    }
    if ($int_pages >= 5){
     echo '[<a href="'.$navigation_url.'5"> <b> 5 </b></a>]';
    }
    

     if ($prev >= 0){
     echo '[<a href="'.$navigation_url.''.$deduct1pages.'">-1</a>]';
    }
    if ($prev20 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct2pages.'">-2</a>]';
    }
    if ($prev30 >= 0){    
    echo '[<a href="'.$navigation_url.''.$deduct3pages.'">-3</a>]';
    }
    if ($prev40 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct4pages.'">-4</a>]';
    }
    if ($prev50 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct5pages.'">-5</a>]';
    }
    if ($prev100 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10pages.'">-10</a>]';
    }
    if ($prev1000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct100pages.'">-100</a>]';
    }
    if ($prev10000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct1000pages.'">-1000</a>]';
    }
    if ($prev100000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10000pages.'">-10000</a>]';
    }
    if ($prev1000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct100000pages.'">-100000</a>]';
    }
    if ($prev10000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct1000000pages.'">-100000</a>]';
    }
    if ($prev100000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10000000pages.'">-1000000</a>]';
    }
    
    echo '<div align="left">';
    if ($next10000000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1000000pages.'">+1000000</a>]';
    }
    if ($next1000000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add100000pages.'">+100000</a>]';
    }
    if ($next100000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add10000pages.'">+10000</a>]';
    }
    if ($next10000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1000pages.'">+1000</a>]';
    }
    if ($next1000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add100pages.'">+100</a>]';
    }
    if ($next100 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add10pages.'">+10</a>]';
    }
    if ($next50 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add5pages.'">+5</a>]';
    }
    if ($next40 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add4pages.'">+4</a>]';
    }
    if ($next30 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add3pages.'">+3</a>]';
    }
    if ($next20 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add2pages.'">+2</a>]';
    }
    if ($next <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1pages.'">+1</a>]';
    }
    
    
    if ($int_pages >= 5){
     echo '[<a href="'.$navigation_url.''.$fifthfromlast.'"><b>Last5</b></a>]';
    }
    if ($int_pages >= 4){
     echo '[<a href="'.$navigation_url.''.$fourthfromlast.'"><b>Last4</b></a>]';
    }
    if ($int_pages >= 3){
     echo '[<a href="'.$navigation_url.''.$thirdfromlast.'"><b>Last3</b></a>]';
    }
    if ($int_pages >= 2){
     echo '[<a href="'.$navigation_url.''.$secondfromlast.'"><b>Last2</b></a>]';
    }
    if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }
echo '';     
echo '<br />';
?>
<br />
<form name="input" action="<?php echo $navigation_url; ?>" method="get">

<?php
if ($_GET['page'] == 0) {
$_GET['page'] = 1;
}
?>
Page:<input onfocus="this.value=''" size="15" type="text" name="page" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="<?php echo $_GET['page']; ?>"/>

<input type="submit" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="Get Page" />

</form>

Link to comment
Share on other sites

True, I just wrote this up and trying to get it out there.

 

So here is the modified and completed for a while, because I don't need this anything else.

 

Example:

http://get.blogdns.com/dynaindex/paginate.php

 

Code:

<?php
//get the url from the address bar
$url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
$url .= "?".$query_string;
}
echo "<a href='$url'>$url</a><br />";

$posts_per_page = 10;//keep this 10 for now, I never got to doing more calculations for everything yet      

//check if the starting row variable was passed in the URL or not
if (!isset($_GET['page']) or !is_numeric($_GET['page'])) {

//we give the value of the starting row to 0 because nothing was found in URL
$startrow = 0;


} else {
//get starting row value from url page bumber and convert
$temp_page=mysql_real_escape_string($_GET['page']);
$convert = $temp_page * $posts_per_page -$posts_per_page;
$startrow = (int)$convert;
}
$startrow=mysql_real_escape_string($startrow);

//conversions of start row for checking and making of pages
$prev = $startrow - 10;
$prev20 = $startrow - 20;
$prev30 = $startrow - 30;
$prev40 = $startrow - 40;
$prev50 = $startrow - 50;
$prev100 = $startrow - 100;
$prev1000 = $startrow - 1000;
$prev10000 = $startrow - 10000;
$prev100000 = $startrow - 100000;
$next = $startrow + 10;
$next20 = $startrow + 20;
$next30 = $startrow + 30;
$next40 = $startrow + 40;
$next50 = $startrow + 50;
$next100 = $startrow + 100;
$next1000 = $startrow + 1000;
$next10000 = $startrow + 10000;
$next100000 = $startrow + 100000;


if ($prev20 <= -20){
$prev20 = $prev20 / 10;
}
if ($prev30 <= -30){
$prev30 = $startrow - 30;
}
if ($prev40 <= -40){
$prev40 = $startrow - 40;
}
if ($prev50 <= -50){
$prev50 = $startrow - 50;
}
if ($prev100 <= -100){
$prev100 = $startrow - 100;
}
if ($prev1000 <= -1000){
$prev1000 = $startrow - 1000;
}
if ($prev10000 <= -10000){
$prev10000 = $startrow - 10000;
}
if ($prev100000 <= -100000){
$prev100000 = $startrow - 100000;
}
if ($prev1000000 <= -1000000){
$prev1000000 = $startrow - 1000000;
}
if ($prev10000000 <= -10000000){
$prev10000000 = $startrow - 10000000;
}
if ($prev100000000 <= -100000000){
$prev100000000 = $startrow - 100000000;
}
if ($next <= +10){
$next = $startrow + 10;
}
if ($next20 <= +20){
$next20 = $startrow + 20;
}
if ($next30 <= +30){
$next30 = $startrow + 30;
}
if ($next40 <= +40){
$next40 = $startrow + 40;
}
if ($next50 <= +50){
$next50 = $startrow + 50;
}
if ($next100 <= +100){
$next100 = $startrow + 100;
}
if ($next1000 <= +1000){
$next1000 = $startrow + 1000;
}
if ($next10000 <= +10000){
$next10000 = $startrow + 10000;
}
if ($next100000 <= +100000){
$next100000 = $startrow + 100000;
}
if ($next1000000 <= +1000000){
$next1000000 = $startrow + 1000000;
}
if ($next10000000 <= +10000000){
$next10000000 = $startrow + 10000000;
}
if ($next100000000 <= +100000000){
$next100000000 = $startrow + 100000000;
}
$deduct1pages = $prev / 10 +1;
$deduct2pages = $prev20 / 10 +1;
$deduct3pages = $prev30 / 10 +1;
$deduct4pages = $prev40 / 10 +1;
$deduct5pages = $prev50 / 10 +1;
$deduct10pages = $prev100 / 10 +1;
$deduct100pages = $prev1000 / 10 +1;
$deduct1000pages = $prev10000 / 10 +1;
$deduct10000pages = $prev100000 / 10 +1;
$deduct100000pages = $prev1000000 / 10 +1;
$deduct1000000pages = $prev10000000 / 10 +1;
$deduct10000000pages = $prev100000000 / 10 +1;
$add1pages = $next / 10 +1;
$add2pages = $next20 / 10 +1;
$add3pages = $next30 / 10 +1;
$add4pages = $next40 / 10 +1;
$add5pages = $next50 / 10 +1;
$add10pages = $next100 / 10 +1;
$add100pages = $next1000 / 10 +1;
$add1000pages = $next10000 / 10 +1;
$add10000pages = $next100000 / 10 +1;
$add100000pages = $next1000000 / 10 +1;
$add1000000pages = $next10000000 / 10 +1;
$add10000000pages = $next100000000 / 10 +1;

//get the page, if none set defaults to page 1
$nav_get = mysql_real_escape_string($_GET['page']);
if (empty($_GET['page'])) {
$nav_get = 1;
}

//the navigation url gets the actual address bar url, then hacks off the get page number value, the navigation itself then replaces the value
$navigation_url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);

if (!empty($_SERVER["QUERY_STRING"])){
$query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
$navigation_url .= "?".$query_string;
}
if ($url == "./" OR $url == "./index.php"){ //you can change these to your needs
$navigation_url = "$navigation_url?&page=1";
}
$navigation_url = trim($navigation_url1,$nav_get);
$navigation_url ="$navigation_url?page=";
//This is where the mysql select would go using the values of LIMIT $startrow,$posts_per_page at end of select statement

//lets just echo these to see what is changing
echo "From mysql startrow $startrow and a max $posts_per_page posts per page<br />";

//total count would be the total items from the same mysql query but not using any limits
$total_count = 345781;//lets just pick some wild number so we can use this with no queries
$total_posts = $total_count;
//using total posts, convert to pages using the last total_count number
$lastposts = $total_posts - $posts_per_page;
$nextposts = $total_posts +1;
$total_posts_pages = $total_posts / $posts_per_page;
list($int,$dec)=explode('.', $total_posts_pages);
$int_pages = $int +1;
$secondfromlast = $int_pages - 1;
$thirdfromlast = $secondfromlast - 1;
$fourthfromlast = $thirdfromlast - 1;
$fifthfromlast = $fourthfromlast - 1;
$page_numbers = $startrow / $posts_per_page;
$total_pages = $total_posts / $posts_per_page;
$page_number = $startrow / $posts_per_page + 1;

if (!$_GET['page']) {
$_GET['page'] = 1;
}

if ($page_number >= $int_pages+1) {
$_GET['page'] = $int_pages;
echo "<h2>That page number exceeded the max pages this result</h2><br />";
}
if ($_GET['page'] <= 0) {
$_GET['page'] = 1;
}
if ($page_number <= 0) {
echo "<h2>That page number was lower than the pages this result</h2><br />";
}

if ($total_posts == 0){
echo '<h2>No results found.</h2>';
}

echo "Page $page_number of $int_pages - $total_posts Results<br />";

//the page navigation hyperlinks
echo '[<a href="./index.php?page=1"><b> New Posts</b></a>]';


if ($prev >= 0){
     echo '[<a href="'.$navigation_url.''.$deduct1pages.'"><b><<- Previous.. </b></a>]';
    }

if ($next <= $nextposts){
    echo '[<a href="'.$navigation_url.''.$add1pages.'"><b> ..Next ->></b></a>]';
    }
?>
   <br />
<?php

if ($int_pages >= 1){
     echo '[<a href="'.$navigation_url.'1"> <b> First </b></a>]';
    } else {
    echo "No Resultss Found For That Search, Please Try A Different One.";
    }
    if ($int_pages >= 2){
     echo '[<a href="'.$navigation_url.'2"> <b> 2 </b></a>]';
    }
    if ($int_pages >= 3){
     echo '[<a href="'.$navigation_url.'3"> <b> 3 </b></a>]';
    }
    if ($int_pages >= 4){
     echo '[<a href="'.$navigation_url.'4"> <b> 4 </b></a>]';
    }
    if ($int_pages >= 5){
     echo '[<a href="'.$navigation_url.'5"> <b> 5 </b></a>]';
    }
    

     if ($prev >= 0){
     echo '[<a href="'.$navigation_url.''.$deduct1pages.'">-1</a>]';
    }
    if ($prev20 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct2pages.'">-2</a>]';
    }
    if ($prev30 >= 0){    
    echo '[<a href="'.$navigation_url.''.$deduct3pages.'">-3</a>]';
    }
    if ($prev40 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct4pages.'">-4</a>]';
    }
    if ($prev50 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct5pages.'">-5</a>]';
    }
    if ($prev100 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10pages.'">-10</a>]';
    }
    if ($prev1000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct100pages.'">-100</a>]';
    }
    if ($prev10000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct1000pages.'">-1000</a>]';
    }
    if ($prev100000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10000pages.'">-10000</a>]';
    }
    if ($prev1000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct100000pages.'">-100000</a>]';
    }
    if ($prev10000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct1000000pages.'">-100000</a>]';
    }
    if ($prev100000000 >= 0){
    echo '[<a href="'.$navigation_url.''.$deduct10000000pages.'">-1000000</a>]';
    }
    
    echo '<div align="left">';
    if ($next10000000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1000000pages.'">+1000000</a>]';
    }
    if ($next1000000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add100000pages.'">+100000</a>]';
    }
    if ($next100000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add10000pages.'">+10000</a>]';
    }
    if ($next10000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1000pages.'">+1000</a>]';
    }
    if ($next1000 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add100pages.'">+100</a>]';
    }
    if ($next100 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add10pages.'">+10</a>]';
    }
    if ($next50 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add5pages.'">+5</a>]';
    }
    if ($next40 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add4pages.'">+4</a>]';
    }
    if ($next30 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add3pages.'">+3</a>]';
    }
    if ($next20 <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add2pages.'">+2</a>]';
    }
    if ($next <= $lastposts){
    echo '[<a href="'.$navigation_url.''.$add1pages.'">+1</a>]';
    }
    
    
    if ($int_pages >= 5){
     echo '[<a href="'.$navigation_url.''.$fifthfromlast.'"><b>Last5</b></a>]';
    }
    if ($int_pages >= 4){
     echo '[<a href="'.$navigation_url.''.$fourthfromlast.'"><b>Last4</b></a>]';
    }
    if ($int_pages >= 3){
     echo '[<a href="'.$navigation_url.''.$thirdfromlast.'"><b>Last3</b></a>]';
    }
    if ($int_pages >= 2){
     echo '[<a href="'.$navigation_url.''.$secondfromlast.'"><b>Last2</b></a>]';
    }
    if ($int_pages >= $int_pages){
     echo '[<a href="'.$navigation_url.''.$int_pages.'"><b>Last</b></a>]';
    }
echo '';     
echo '<br />';
?>
<br />
<form name="input" action="<?php echo $navigation_url; ?>" method="get">

<?php
if ($_GET['page'] == 0) {
$_GET['page'] = 1;
}
?>
Page:<input onfocus="this.value=''" size="15" type="text" name="page" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="<?php echo $_GET['page']; ?>"/>

<input type="submit" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value="Get Page" />

</form>

Link to comment
Share on other sites

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.