Jump to content

PREVIOUS and NEXT


The Little Guy

Recommended Posts

How would you do PREVIOUS, and NEXT links from an array using the keys of the array?

When there are no more keys in the array, the next link will say First.

When there are no previous keys in the array, the prev link will say Last.

 

I don't know if my brain is dead, or I just don't know, but I cannot get this.

Link to comment
https://forums.phpfreaks.com/topic/43319-previous-and-next/
Share on other sites

<?php

$pagein = $_GET["pagein"];
$rowmax = "20";
if(!isset($pagein)) { 
          $pagein = 0; 
 }

  $query = "SELECT * FROM table WHERE text LIKE '%$searchterm%' OR coding LIKE '%$searchterm%'   LIMIT  $pagein, $rowmax";

$num_rows = mysql_num_rows($query);

 if(isset($pagein)) { $read2 = $pagein-$rowmax; }

 if($pagein > 0) {
 	$resultsin = $pagein;
echo "<a href='index.php?searchterm=$searchterm&pagein=$read2'>« Prev 20 Results</a> ";
}
 $read = $pagein+$rowmax;
 
if($num_rows > $pagein+$rowmax) {
$resultsout =  $pagein+$rowmax;
}
if($num_rows < $pagein+$rowmax) {
$resultsout =  $num_rows;
}
if($num_rows > ($pagein+$rowmax)) {
$f = ($num_rows - ($pagein+$rowmax));
if($f < $rowmax) {
$fy = $f;	
}

if($f > $rowmax) {
$fy = "20";	
}
//  if($pagein > 1) {
//	$resultsin = $pagein;
//}
 if($pagein == 0) {
$resultsin = "1";
}
if(($pagein > 0) & ($num_rows > $pagein+$rowmax)) {
echo"&#124; ";

}
echo "<a href='index.php?searchterm=$searchterm&pagein=$read'>Next $fy Results &raquo</a><br />";
} 

?>

Link to comment
https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210961
Share on other sites

There!!! I think it works now!!!

 

Here is the code I used:

 

after I made my SQL:

<?php
while($garray = mysql_fetch_array($girls)){
$gid .= $garray['id'];
}
$g = str_split($gid);
print_r($g);
$key = array_search($id,$g);
$mode = current($g);
for($i=0;$i<$key;$i++){
$mode = next($g);
}
$mode = prev($g);
if($mode == ""){
$mode = end($g);
}
echo '<a href="next.php?id='.$mode.'">Previous</a>';
$mode = reset($g);
for($i=0;$i<$key;$i++){
$mode = next($g);
}
$mode = next($g);
if($mode == ""){
$mode = reset($g);
}
echo '<a href="next.php?id='.$mode.'">Next</a>';
?>

Link to comment
https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210969
Share on other sites

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.