The Little Guy Posted May 2, 2007 Share Posted May 2, 2007 OK, I have a page that displays 1 image, I am trying to make next / previous links, they will look somthing like this: <a class="bodyLink" href="enlargeImage?userID=1&id=13">Next</a> Then when the user clicks on next, and the new page displays, the Next link could look something like this: <a class="bodyLink" href="enlargeImage?userID=1&id=25">Next</a> Notice the bold words in each, the next/previous id variable may not be in 1,2,3 order, but in 1,5,10 order. So... how do I make next/previous links like this? Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/ Share on other sites More sharing options...
paul2463 Posted May 2, 2007 Share Posted May 2, 2007 have three javascript variables and write a small javascript function, something like var prev = ""; var now = "" var next = ""; function prevNext() { prev = now; now = next; next = however you get the next image number; } then use the variables prev and next <a class="bodyLink" href="enlargeImage?userID=1&id=" + prev>Previous[/url] <a class="bodyLink" href="enlargeImage?userID=1&id=" + next>Next[/url] then run the function onclick of an image link Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/#findComment-243625 Share on other sites More sharing options...
The Little Guy Posted May 2, 2007 Author Share Posted May 2, 2007 next = however you get the next image number; I don't know how to get the next image number Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/#findComment-243641 Share on other sites More sharing options...
paul2463 Posted May 2, 2007 Share Posted May 2, 2007 where are the image number coming from them, you must be showing them in some sort of order, are they generated via database query etc??? Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/#findComment-243642 Share on other sites More sharing options...
The Little Guy Posted May 2, 2007 Author Share Posted May 2, 2007 $sql = mysqli_query($db,"SELECT * FROM default_images WHERE userID = '$userID' ORDER BY id ASC")or die(mysqli_error($db)); $row = mysqli_fetch_array($sql); $count = mysqli_num_rows($sql); Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/#findComment-243646 Share on other sites More sharing options...
paul2463 Posted May 2, 2007 Share Posted May 2, 2007 then no function is required <?php $sql = mysqli_query($db,"SELECT * FROM default_images WHERE userID = '$userID' ORDER BY id ASC")or die(mysqli_error($db)); $count = mysqli_num_rows($sql); while($row = mysqli_fetch_array($sql)) { $picArray[] = $row['picture number']; //place all picture codes into an array } ?> then for your next and previous links <a class="bodyLink" href="enlargeImage?userID=1&id="<?php echo prev($picArray); ?> >Previous</a> <a class="bodyLink" href="enlargeImage?userID=1&id="<?php echo next($picArray); ?> >Next</a> the code has been edited from its origional, if you are looking at it again I have made correct the next / prev code Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/#findComment-243653 Share on other sites More sharing options...
The Little Guy Posted May 2, 2007 Author Share Posted May 2, 2007 This doesn't work: <?php $sql = mysqli_query($db,"SELECT * FROM default_images WHERE userID = '$userID' ORDER BY id ASC")or die(mysqli_error($db)); while($row = mysqli_fetch_array($sql)){ $picArray[] = $row['id']; //place all picture codes into an array } echo' <p style="text-align:center"> <a class="bodyLink" href="enlargeImage?userID='.$userID.'&id='.prev($picArray).'" >Previous</a> | <a class="bodyLink" href="enlargeImage?userID='.$userID.'&id='.next($picArray).'" >Next</a> </p>'; ?> If it helps, here is the page: http://auto.tzfiles.com/enlargeImage?userID=1&id=5 the next link should go to this one: http://auto.tzfiles.com/enlargeImage?userID=1&id=12 Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/#findComment-243658 Share on other sites More sharing options...
paul2463 Posted May 2, 2007 Share Posted May 2, 2007 I have had a go at something else, as the page is refreshed when the image changes try this <?php $sql = mysqli_query($db,"SELECT * FROM default_images WHERE userID = '$userID' ORDER BY id ASC")or die(mysqli_error($db)); while($row = mysqli_fetch_array($sql)){ $picArray[] = $row['id']; //place all picture codes into an array } $count = count($picArray); if (isset($_GET['arrid'])) { $arrid = $_GET['arrid']; if($arrid == "") { $arrid = 0; } if ($arrid < $count - 1) { $previd = $arrid-1; $nexid = $arrid+1; $prev = $picArray[$previd]; $next = $picArray[$nexid]; } } ?> then <p style="text-align:center"> <a class="bodyLink" href='enlargeImage?userID=<?php echo $userID; ?>&arrid=<?php echo $previd; ?>&id=<?php echo $prev; ?>'>Previous</a> <a class="bodyLink" href='enlargeImage?userID=<?php echo $userID; ?>&arrid=<?php echo $nexid; ?>&id=<?php echo $next; ?>'>Next</a> </p> I have sent across with the id a value called arrid, which is the array key variable, the php function then assigns all the variables that are needed for the next and previous Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/#findComment-243745 Share on other sites More sharing options...
The Little Guy Posted May 4, 2007 Author Share Posted May 4, 2007 OK... I got it, and if anyone wants to know how... Here it is: <?php $sql = mysqli_query($db,"SELECT * FROM default_images WHERE userID = '$userID' ORDER BY id ASC")or die(mysqli_error($db)); while($row = mysqli_fetch_array($sql)){ $idArray[] = $row['id']; } $key = array_search($id,$idArray); $mode = current($idArray); for($i=0;$i<$key;$i++){ $mode = next($idArray); } $mode = prev($idArray); if($mode == ""){ $mode = end($idArray); } echo' <p style="text-align:center"> « <a class="bodyLink" href="enlargeImage?userID='.$userID.'&id='.$mode.'" >Previous</a> |'; $mode = reset($idArray); for($i=0;$i<$key;$i++){ $mode = next($idArray); } $mode = next($idArray); if($mode == ""){ $mode = reset($idArray); } echo' <a class="bodyLink" href="enlargeImage?userID='.$userID.'&id='.$mode.'" >Next</a> » </p>'; ?> Link to comment https://forums.phpfreaks.com/topic/49689-solved-next-previous-links/#findComment-245436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.