Forum Moderators: open
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Location where the images are stored
$file_path = 'http://www.mysite.com/holidays/files/photo_big/';
// Fetch the data for the pictures
$sql = "SELECT `photo_id`, `photo_caption_1` , `photo_listing`
FROM `listing_photo`
WHERE `photo_listing`= 127
LIMIT 10";
$result = mysql_query($sql) or trigger_error(mysql_query(), E_USER_ERROR);
// Display each picture
while($row = mysql_fetch_assoc($result)){
$src = $file_path . $row['photo_id'] . ".jpg";
$number = 2;
if($number % 2 == 0) {
echo '$number';
}
else {
echo '$number';
}
?>
<div class="Image">
<img src="<?=$src?>" alt="<?=$row['photo_caption_1']?>" title="<?=$row['photo_caption_1']?>"><br>
<span><?=$row['photo_caption_1']?></span>
</div>
<?php } ?> [edited by: whoisgregg at 10:20 pm (utc) on Mar 10, 2010]
[edit reason] Whoops, no URLs please. See TOS [webmasterworld.com] :) [/edit]
<?php
$sql = "SELECT `photo_id`, `photo_caption_1` , `photo_listing`
FROM `listing_photo` WHERE `photo_listing`= 127 LIMIT 10";
$colcount=0;
$imgContent=NULL;
$result = mysql_query($sql) or trigger_error(mysql_query(), E_USER_ERROR);
//
while($row = mysql_fetch_assoc($result)){
$src = $file_path . $row['photo_id'] . ".jpg";
$cap = $row['photo_caption_1'];
// Set the CSS selector width for Image so it only fits two in
// the selector "column". Then you won't need the meaningless <br>.
// Then do: .Image p { margin 0; padding 6px 0 0 0; text-align:center; }
// span also has no semantic "meaning." This solution also
// requires a clearing element: .clear-div { clear:both; }
if ($colcount == 0) { $imgContent .= '<div class="column">'; }
$imgContent .= "
<div class=\"Image\">
<img src=\"$src\" alt=\"$cap\" title=\"$cap\">
<p>$cap</p>
</div>
";
$colcount++;
if ($colcount>=2) { $colcount=0; $imgContent .= '<div class="clear-div"></div></div>'; }
}
// If there is an odd number of images, close the last div
if ($colcount > 0) { $imgContent .= '<div class="clear-div"></div></div>'; }
if ($imgContent) { echo $imgContent; }
else { echo '<p>No images to display.</p>'; }
?>
<div class="column">
<div class="Image">
<img src="115.jpg" alt="Lounge" title="Lounge">
<p>Lounge</p>
</div>
<div class="Image">
<img src="116.jpg" alt="Pool" title="Pool">
<p>Pool</p>
</div>
<div class="clear-div"></div></div><div class="column">
<div class="Image">
<img src="117.jpg" alt="Shaded Seating" title="Shaded Seating">
<p>Shaded Seating</p>
</div>
<div class="Image">
<img src="118.jpg" alt="Naya" title="Naya">
<p>Naya</p>
</div>
<div class="clear-div"></div></div><div class="column">
<div class="Image">
<img src="119.jpg" alt="Twin Bedroom" title="Twin Bedroom">
<p>Twin Bedroom</p>
</div>
<div class="Image">
<img src="120.jpg" alt="Villa Helena Javea" title="Villa Helena Javea">
<p>Villa Helena Javea</p>
</div>
<div class="clear-div"></div></div>
[edited by: jatar_k at 5:31 pm (utc) on Mar 11, 2010]
[edit reason] pasted code, no urls thanks [/edit]