hi everybody,
im trying to make next and previous buttons. im displaying record based on a search. when any image on the search results is clicked then dat image opened in a new page with details about dat imgae on a seperate page. lets say this image as a coupon. now im trying to navigate to next and previous records without going back.
Doing this way im storing all searched ids in an array. this code is at the search results page. and image details page contains the following code.
when an image is clicked at the search results page im redirecting user to image details page and passing id in the url. so i know the current value in the session variable. i have googled around about it but i didnt get any useful solution of it. i tried the following function from php.net:
i failed to get the values instead of keys. please tell me how i can get the values. thanx
im trying to make next and previous buttons. im displaying record based on a search. when any image on the search results is clicked then dat image opened in a new page with details about dat imgae on a seperate page. lets say this image as a coupon. now im trying to navigate to next and previous records without going back.
Code:
while($resultSet = mysql_fetch_assoc($que)){
$np[] = $rs['item_id'];
}
$_SESSION['np']= $np;
Code:
foreach($_SESSION['np'] as $key=>$value){
$nps[] = $value;
}
$nps = implode(",",$nps);
$numresults=mysql_query("select * from discount_items where item_id IN($nps)");
Code:
function array_key_relative($array, $current_key, $offset = 1) {
// create key map
$keys = array_keys($array);
// find current key
$current_key_index = array_search($current_key, $keys);
// return desired offset, if in array, or false if not
if(isset($keys[$current_key_index + $offset])) {
return $keys[$current_key_index + $offset];
}
return false;
}
$next_key = array_key_relative($test_array, $_REQUEST['id'], 1);
$prev_key = array_key_relative($test_array, $_REQUEST['id'], -1);
echo "<a href='image_details?id=$next_key'>Next</a><a href='image_details?id=$prev_key'>Previous</a>"
Comment