Ok I am very close but I need help building an array and have it display the $row based on a $_GET variable number in the URL- I want to show one image from an album and have a 'NEXT' button so that I can cycle though all the images in that album. This is a very small/simple gallery, all images will be in one table as shown below.
I have a simple table containing a path to an image, a caption, and an album_id so I can know what album the image is associated with.
[code]album_id | path | caption
1 | image1.jpg | This is caption #1
1 | image2.jpg | This is caption #2
2 | image3.jpg | This is caption #3
3 | image4.jpg | This is caption #4
1 | image5.jpg | This is caption #5[/code]
I need to build an array based on SELECT * FROM table WHERE album_id='1' -- Like this (very crude):
$row[0] = image1.jpg
$row[1] = image2.jpg
$row[2] = image5.jpg
So with this array, I need to match it with a corresponding variable which counts the total number of returned results (in this case 3.) I have this functionality setup with a 'next' button shown in the code below. It will count through the three returned results through a GET variable $i +1.
How can I match everything up so that it will get the variable from the URL $GET['id'] = 2 (for example) and know that its on the second image and it needs to pull the second image from the array ($row[1] = image2.jpg)? If $GET['id'] = 3, it will know to get the third image in the array and return $row[2] = image5.jpg.
$query = "SELECT * FROM resort_photo WHERE r_id='1'";
$result = mysql_query($query) or die(mysql_error());
$pic = (mysql_fetch_array(mysql_query($query)));
$max = mysql_num_rows($result);
echo "There are ".$max." photos!<p>";
if ($_GET['i'] == $max || $_GET['i'] > $max) {
$next = 1;
} else {
$next = $_GET['i'] + 1;
}
echo "<a href=\"test2.php?i=" . $next . "\">Next</a>";
// NEED HELP HERE TO BUILD ARRAY- I need to build an array and have it corrospond to the $_GET['i'] above.
echo $pic['path']; // This only returns the first row of the query "image1.jpg"