I'm tearing the old hair out over this one.
I'm setting up a simple photo portfolio. I have a single php page which querys MySQL and displays a photo and a few other bits of info.
The photos are organised in sets and I've got a script to see how many photos are in each set.
I also have Previous and Next navigation and numbering for orientation. It's this that is proving to be quite stubborn.
I have one query string variable $image which pulls the correct imnage from the db. I've managed to use this to construct the Previous and Next links and the numbering but only if the images in a particular set have contiguous IDs in the db. Ideally I'd have it work out the Previous and Next bits based on an array returned from the db so I can have non contiguous entries. For example I have IDs 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and 37 belonging to my ny group.
I'm getting the IDs from the db and looping them into an Array like this:
$setQuery = "SELECT photo_id
FROM photo
WHERE cat_id = \"$theCat\"";
if(!($setTotal = @ mysql_query ($setQuery, $connection)))
showerror();
$rowsFound = @ mysql_num_rows($setTotal);
$rowArray = array();
for($i=0;
$i<=$rowsFound;
$i++)
{
array_push($rowArray, @ mysql_fetch_array($setTotal));
}
If I print_r the Array I get this horrible 2 dimensional array:
Array ( [0] => Array ( [0] => 1 [photo_id] => 1 ) [1] => Array ( [0] => 2 [photo_id] => 2 ) [2] => Array ( [0] => 3 [photo_id] => 3 ) [3] => Array ( [0] => 4 [photo_id] => 4 ) [4] => Array ( [0] => 5 [photo_id] => 5 ) [5] => Array ( [0] => 6 [photo_id] => 6 ) [6] => Array ( [0] => 7 [photo_id] => 7 ) [7] => Array ( [0] => 8 [photo_id] => 8 ) [8] => Array ( [0] => 9 [photo_id] => 9 ) [9] => Array ( [0] => 10 [photo_id] => 10 ) [10] => Array ( [0] => 37 [photo_id] => 37 ) [11] => )
That's ok to an extent as I can get the Array length to determine the total number in the set.
However I want to search the Array to find out where I am in it (i.e. the relevant key in the Array) without using the present image number ($image) so I'm trying to do this:
$current = array_search($image, $rowArray);
$image is the same as my required photo_id in the Array. I was hoping this would give me the key in the Array of the photo currently displayed. That way I'd be able to use this key to count backwards or forwards in the Array to skip beteen any image ID.
Trouble is I get a Null return on the array_search().
Does anybody know why this is? My guess is the search can't look into the two dimensional Array and so it comes back with nothing since the photo_id's are all in the Arrays within the Array. is there a better way of constructing the Array so it's a simple one with a list of keys and image_id's only?
Sorry for ramblin' on. Thanks all for your help in advance. 🙂