next / previous buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    #1

    next / previous buttons

    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.

    Code:
    while($resultSet = mysql_fetch_assoc($que)){
    $np[] = $rs['item_id'];
    }
    $_SESSION['np']= $np;
    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.

    Code:
    foreach($_SESSION['np'] as $key=>$value){
    $nps[] = $value;
    }
    $nps = implode(",",$nps);
    $numresults=mysql_query("select * from discount_items where item_id IN($nps)");
    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:

    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>"
    i failed to get the values instead of keys. please tell me how i can get the values. thanx
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    #2
    ok i got the solution myself :)). just by changing array_keys to array_values. it worked.

    Comment

    Working...