Wednesday, 4 September 2013

How can i put these array images into seperate divs?

How can i put these array images into seperate divs?

This PHP code generates three pictures, with three quotes. I've been
struggling for the past few days, so how can I make it to generate each
image and text into a new div tag? This is the code:
<div id="randown" style="width: 475px; left: 10px; top: 15px; height:
89px;"class="style4">
<?php
define('RANDOM_IMAGES_COUNT2',3);
define('RANDOM_IMAGES_FORMAT2', '<img src="%s"
style="width:177px;height:100px;border-
style:solid;border-width:2px;border-color:black;" /><a href="%s" alt="%s"
title2="%s">%s</a>');
#------------------------------------------------------------------------------
$images = array (
array ( 'title2' => 'Test 2', 'src2' => 'pic2.jpg', 'href2' =>
'http://mylink.com/path/','text2' => 'Hello' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic7.jpg', 'href2' =>
'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic9.jpg', 'href2' =>
'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic5.jpg', 'href2' =>
'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic3.jpg', 'href2' =>
'http://mylink.com/path/','text2' => 'Hello3' )
);
#------------------------------------------------------------------------------
if ( count($images) < RANDOM_IMAGES_COUNT2 ) {
trigger_error('Not enough images given', E_USER_WARNING);
exit;
}
#------------------------------------------------------------------------------
for ($i = 0; $i < RANDOM_IMAGES_COUNT2; $i++) {
shuffle($images);
$tmp = array_shift($images);
printf( RANDOM_IMAGES_FORMAT2, $tmp['src2'], $tmp['href2'],
$tmp['title2'], $tmp['title2'],$tmp['text2'] ); }
?>
</div>

No comments:

Post a Comment