CREATING A DYNAMIC ONLINE GALLERY 6. Clicking the (Web server extensions)

CREATING A DYNAMIC ONLINE GALLERY 6. Clicking the thumbnails still doesn t do anything, so you need to create the logic that changes the main image and its associated caption. Locate this section of code in the block above the DOCTYPE declaration: // get the name and caption for the main image $mainImage = $row[’filename’]; $caption = $row[’caption’]; Highlight the line that defines $caption, and cut it to your clipboard. Wrap the other line in a conditional statement like this: // get the name for the main image if (isset($_GET[’image’])) { $mainImage = $_GET[’image’]; } else { $mainImage = $row[’filename’]; } The $_GET array contains values passed through a query string, so if $_GET[’image’] has been set (defined), it takes the filename from the query string and stores it as $mainImage. If $_GET[’image’] doesn t exist, the value is taken from the first record in the result set as before. 7. You finally need to get the caption for the main image. It s no longer going to be the same every time, so you need to move it to the loop that displays the thumbnails. It goes right after the opening curly brace of the loop. Position your cursor after the brace and insert a couple of lines, and then paste the caption definition that you cut in the previous step. You want the caption to match the main image, so if the current record s filename is the same as $mainImage, that s the one you re after. Wrap the code that you have just pasted in a conditional statement like this: 329
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Leave a Reply