Array from ID: ok,done. But How to use it correctly?

Hi all,
I looked after and found lots of useful info on the current(), next(), functions that can be applied to an array. But i cannot find the simplest manner of doing this.

Actually, my goal is to browse through selected keys (that are in fact id’s of my selected rows). The browsing is driven by a single ‘next’ link that will go for the following record until It discovers that there is no records, then I will go for another set of Id’s. Simple, eh?
In fact, I’m stuck at finding the current ‘key’ once I go forward in the array : (i.e the link has been clicked, say once for example, then where am I?)

Here is my code below :

//Search for pictures that shares the same item_id. pict_id is my PK and pict_name is the link to the file, and obvisouly i want that the browsing will be ordered alphabetically) 

$query="SELECT pict_id FROM fb_picts WHERE fb_picts.item_id='$item_id' ORDER BY pict_name ASC"; 
$result=@mysql_query($query,$connexion); 

//declaring an empty array 
$allImg = array(); 

//Filling the array with pict_id's 
while ($allRows = mysql_fetch_object($result)) { 
  $allImg[$allRows->pict_id][] = $allRows; 
} 

//Okay, now just for the testing, I echoed the array of 'keys' means the id of the pictures. I looks great, as they are non-consecutive figures and sorted the way I want. 

foreach ($allImg  as $key => $value) { 
    echo $key."<br />"; 
} 


//Now for the hard part. I tried several solutions, but I'm stuck.
//What is the current ID displayed ? 

$currId= current($allImg[0]); //does not work

//What is the next ID to be displayed 
$nextId= next($allImg[]);  //doesn't work either...


//Finally, all I want is the link,once clicked, will retrieve the next ID 
echo "<a href='$PHP_SELF?cat=$cat_id&item=$item_id&id=$nextId'>next</a>"; 

Eventually, this does not work at all. Except for the array part, I cannot navigate through my id’s and cannot applied the correct id to the image to be displayed…

So, my main problems are :

**- Once stored in my array ‘$allImg’ , how can I verify which pict_id is being displayed ?

  • How does the ‘$nextId’ increments by itself once clicked ?**

Thanks in advance for any efficient answer :slight_smile:

Below is a schema of my main .php catalog system attached

K.