The Little Guy Posted March 19, 2007 Share Posted March 19, 2007 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 More sharing options...
The Little Guy Posted March 20, 2007 Author Share Posted March 20, 2007 bump Link to comment https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210937 Share on other sites More sharing options...
rcorlew Posted March 20, 2007 Share Posted March 20, 2007 What kind of array are you talking about, single level, multidimensional or sql array?? Link to comment https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210951 Share on other sites More sharing options...
The Little Guy Posted March 20, 2007 Author Share Posted March 20, 2007 if I do a print_r... I get this: Array ( [0] => 5 [1] => 3 [2] => 1 [3] => 2 [4] => 4 ) It was generated from my SQL. Link to comment https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210952 Share on other sites More sharing options...
redarrow Posted March 20, 2007 Share Posted March 20, 2007 try sort($array_name); Link to comment https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210954 Share on other sites More sharing options...
The Little Guy Posted March 20, 2007 Author Share Posted March 20, 2007 its already sorted the way I want it to be sorted. Link to comment https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210955 Share on other sites More sharing options...
redarrow Posted March 20, 2007 Share Posted March 20, 2007 read this ok. http://www.phpfreaks.com/tutorials/43/1.php Link to comment https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210957 Share on other sites More sharing options...
rcorlew Posted March 20, 2007 Share Posted March 20, 2007 <?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"| "; } echo "<a href='index.php?searchterm=$searchterm&pagein=$read'>Next $fy Results »</a><br />"; } ?> Link to comment https://forums.phpfreaks.com/topic/43319-previous-and-next/#findComment-210961 Share on other sites More sharing options...
The Little Guy Posted March 20, 2007 Author Share Posted March 20, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.