On Sat, 2006-09-09 at 16:49 +0200, Reinhart Viane wrote: > 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 Untested... ... ... <?php if( ($result = mysql_query( $query )) === false ) { // do something other than die you lazy ass programmers. } else { $hits = mysql_num_rows( $result ); $cols = 3; $rows = ceil( $hits / $cols ); for( $i = 0; $i < $rows; $i++ ) { for( $j = 0; $j < $cols; $j++ ) { $picture = ''; if( ($item = mysql_fetch_assoc( $result )) !== false ) { echo '<td width="120" valign="top">' .$item['picture'] .'</td>' .'<td width="13" valign="top">' .'<!--DWLayoutEmptyCell--> ' .'</td>'; } } } } ?> Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php