mstevens Posted October 25, 2014 Share Posted October 25, 2014 Good evening, I am working on a program that takes images, and casts them into an associated array, I then want to display thumbnails of those images into a 3 column by 4 row table... [image][image][image] [image][image][image] [image][image][image] [image][image][image] (For my visual friends) here is my current, pardon for the mess, but right now, functionality is more important. <!DOCTYPE html> <html> <head> <title>Zodiac Gallery</title> </head> <body> <h2 style="text-align:center">Zodiac Gallery</h2> <p>Click a thumbnail image to see enlarged view.</p> <?php $ZodiacArray = array ( "Images/rat.jpg" => "Rat", "Images/ox.jpg" => "Ox", "Images/tiger.jpg" => "Tiger", "Images/rabbit.jpg" => "Rabbit", "Images/dragon.jpg" => "Dragon", "Images/snake.jpg" => "Snake", "Images/horse.jpg" => "Horse", "Images/goat.jpg" => "Goat", "Images/monkey.jpg" => "Monkey", "Images/rooster.jpg" => "Rooster", "Images/dog.jpg" => "Dog", "Images/pig.jpg" => "Pig"); foreach ($ZodiacArray as $image => $zodiac) { echo "<table> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> <tr> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> <td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td> </tr> </table>"; ?> Help is welcome, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/292047-php-insert-an-associated-array-variable-into-a-table/ Share on other sites More sharing options...
jcbones Posted October 25, 2014 Share Posted October 25, 2014 (edited) So basically, echo "<table>"; $i = 0; foreach ($ZodiacArray as $image => $zodiac) { echo ($i % 4 == 0) ? <tr> : null; echo '<td><img src="$image" alt="$zodiac" style="width:68px;height:65px"></td>'; echo ($i++ % 4 == 0) ? </tr> : null; } echo '</table>'; I think that is error free, but as always, I could be wrong. Edited October 25, 2014 by jcbones Quote Link to comment https://forums.phpfreaks.com/topic/292047-php-insert-an-associated-array-variable-into-a-table/#findComment-1494662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.