--->
Setting Up Your Array PHP File
Step 1:
Create your array by creating a new .php document.
Step 2:
In the example for L05_req_array.php, we created a document that would list all the gallery values. That way when we write our other php files, we can use php to call link to this file.
Step 3:
The first step is to initialize the array by using $gallery = array(); Do this in your req_array.php document.
Step 4:
Then you can create the array values such as $gallery[ ] ='halfDome1';
$gallery[ ] ='halfDome2';
Step 5:
Finally, create the counter for the array: $arrCount = count($gallery); and close out the php.
--->
EXAMPLE: L05_gallery.php
--->
This example shows two things: 1) using an array to set up a dropdown menu of gallery images via a form to return a larger image, and 2) returning the same thing via thumbnail images that act as a links.
Step 1:
Form Array - Drop down: First create your new .php document.
Step 2:
Add your req_array.php to the top of your new document.
<? php
require_once('L05_req_array.php');
?>
Step 3:
Then in the body, add a form field through Dreamweaver.
Step 4:
Inside, put a dropdown menu and make its ID = imageID, and a submit button.
Step 5:
Select your form field and set the Method to GET.
Step 6:
Set the Action to L05_galleryEnlarged.php (your document that will process the GET function and return your desired image).
Step 7:
Hit list items in Dreamweaver and insert label 1, label 2, value 1, value 2. (This should set up the following php in your form). If not, write a for loop in the dropdown to assign a number value that varies, and options those values.
<?php for ($i=0; $i < $arrCount; $i++) { ?>
<option value="<?php echo $i; ?>" selected="selected"><?php echo $gallery[$i];?></option>
<?php } ?>
Step 8:
Thumbnail Array - Images: First create your new .php document.
Step 9:
You can insert the following for loop in your document and break it up to be an anchor link. Also break up the image tag.
<?php
for ($i=0; $i < $arrCount; $i++)
{
echo '<a href="L05_galleryEnlarged.php?imageID=';
echo $i;
echo '">';
echo '<img src="gallery/';
echo $gallery[$i];
echo '_thumb.jpg" width="200" height="100" />';
echo '</a>';
}
?>
Step 10:
The above code says that if you click on an image link, it will return the enlarged image from the gallery. Notice how the anchor tag and image tags are broken up in php.
Step 11:
Save that file and create a new document described in step 6 above. L05_galleryEnlarged.php.
Step 12:
In the new file, list your gallery by using the require once code.
Step 13:
Write an IF loop with isset for the GET Method and echo the variable imageID.
<?php
require_once('L05_req_array.php');
if (isset($_GET['imageID'])) //has form been submitted?
{
$imageID = $_GET['imageID'];
}
else
{
$imageID = 1; //if no form submitted, lets create a default choice so an image displays
}
echo $imageID;
?>
Step 14:
Finally echo back the imageID from the gallery array in the IMG tag wrapped in php as shown below:
<img src="gallery/<?php echo $gallery[$imageID]; ?>.jpg" width="500" />
Step 15:
Thats it! Test out in MAMP if it works.