while() function.... new lines after every 5 entries?
Posted: Sun Feb 26, 2006 6:44 am
feyd | Please use
You can view what is currently happening at http://www.spartacusband.com/gallery.php
Thanks
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi guys,
I'm using the while() function to create a picture gallery. The code gets the image titles from a database and if they are in the selected gallery they display them. However, I would like them to display 5 images together and then insert a < br >.
How is this possible?
Heres the code I have so far (note: the database connection is already open)Code: Select all
<?php
if (!$_GET[gallery]) {
$sel_gal = "1";
} else {
$sel_gal = $_GET['gallery'];
}
$getpics = "select * from gallery where gallery = $sel_gal";
$getpics_res = mysql_query($getpics, $conn) or die(mysql_error());
$num_pic_in_gal = mysql_num_rows($getpics_res);
if ($num_pic_in_gal = "0") {
$display = "There are no pictures in this gallery";
} else {
$display = "<DIV
style=\"padding:0px; MARGIN: 0px; OVERFLOW: auto; BORDER-LEFT: 1px solid gray; WIDTH: 852; BORDER-BOTTOM: 1px solid gray; HEIGHT: 299\">
<TABLE cellSpacing=0 cellPadding=0 border=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\">
<COLGROUP>
<COL width=100%>
<TBODY>
<TR>
<TD class=description vAlign=top noWrap width=841>
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\">
<tr>";
while ($picarray = mysql_fetch_array($getpics_res)) {
$thumb = $picarray['picID'];
if (mb_strlen($thumb) == "1") {
$thumb1 = "00";
$thumb1 .= $thumb;
} else if (mb_strlen($thumb) == "2") {
$thumb1 = "0";
$thumb1 .= $thumb;
} else {
$thumb1 = $thumb;
}
$maxpics = "5";
$display .= "<td><img src=\"http://www.spartacusband.com/gallery/thumbnails/".$thumb1.".jpg\"></td>";
}
$display .="</tr>
</table>
</TD>
</TR>
</TBODY></TABLE></DIV>";
}
echo $display;
?>You can view what is currently happening at http://www.spartacusband.com/gallery.php
Thanks
feyd | Please use
Code: Select all
andCode: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]