loop structure
| From: | Reinhart Viane | Date: | Sat, 09 Sep 2006 14:49:20 +0000 |
| Subject: | loop structure | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-241531@lists.php.net to get a copy of this message | ||
I've been experimenting some time now but i can't get it right.
I have a database in which I have a table with a list of photo_url
Table: photos
Id photo_url
1 photos/boeket_s40.jpg
2 photos/boeket_k12.jpg
3 photos/boeket_z23.jpg
...
I get this out of the database with this query:
$sqlphoto="select * from photos where photo_type='$category'";
$exephoto=mysql_query($sqlphoto) or die (mysql_error());
Now I need a loop so that the photos are put into a table:
<table width="420" border="0" cellpadding="0"
cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="17" height="110"
valign="top"><!--DWLayoutEmptyCell--> </td>
<td width="120" valign="top">PICTURE HERE</td>
<td width="13"
valign="top"><!--DWLayoutEmptyCell--> </td>
<td width="120" valign="top"> PICTURE HERE </td>
<td width="13"
valign="top"><!--DWLayoutEmptyCell--> </td>
<td width="120" valign="top"> PICTURE HERE </td>
<td width="13"><!--DWLayoutEmptyCell--> </td>
<td width="4"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="15"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
The first <tr> must be looped as long as there are photos in the array (so
something like #lines in array/3, with ceil())
In each <tr> there are 3 pictures in it's <td> tags:
so maybe something like
for ($i=1;$i<3;$i++){
<td width="120" valign="top">PICTURE HERE</td>
<td width="13"
valign="top"><!--DWLayoutEmptyCell--> </td>
}
I have tried several thing and I'm able to create the correct amount of rows
and the loop for the 3 cells in the row.
Unfortunately it always only shows the first picture from the array in each
of those cells.
Can someone help me out? THX