Re: How to generate a 3-column-table layout from an array of pictures.
| From: | David Eisenhart | Date: | Wed, 04 Dec 2002 17:14:03 +0000 |
| Subject: | Re: How to generate a 3-column-table layout from an array of pictures. | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6638@lists.php.net to get a copy of this message | ||
Just coded something similar (I have NOT properly tested this but it appears
to be working nicely). Basically creating an array of picture file
references (taking care to pad out any empty cells in the last row) and
passing this to the template which unpacks it and constructs the table
around it.
Hope that this helps,
David Eisenhart
:---------------------------------------------------------------
:---------------------------------------------------------------
In php file
... database query stuff here ...
$num_rows = @ mysql_num_rows($result);
if ($num_rows > 0) {
DEFINE ('NUM_PICS_PER_ROW', 3);
$pics = array();
$row_num = 0;
$cell_num = 0;
while ($row = mysql_fetch_array($result)) {
$pics[$row_num][$cell_num] = array($row['FileName'], $row['PhotoID']);
$cell_num ++;
$completed_row = FALSE;
if ($cell_num == NUM_PICS_PER_ROW){
$row_num ++;
$cell_num = 0;
$completed_row = TRUE;
}
}
if (!$completed_row){
$pics[$row_num] =
array_pad($pics[$row_num],NUM_PICS_PER_ROW,'(blank)');
}
$smarty->assign(array('pictures' => $pics,
'search_string' => $user_search_input));
:---------------------------------------------------------------
:---------------------------------------------------------------
In template file:
<table border="0" cellspacing="0" cellpadding="0"
align="center">
{section name="row" loop=$pictures}
<tr valign="top">
{section name="cell" loop=$pictures[row]}
<td width="180" height="220">
{if $pictures[row][cell] != "(blank)"}
(html to present image {$pictures[row][cell][0]} goes
here )
{else}
{/if}
</td>
{/section}
</tr>
{/section}
</table>
"Peter Schumacher" <peter@schumacher.dk> wrote in message
news:20021204152801.97281.qmail@pb1.pair.com...
> Anyone knows how to generate a 3-column-table layout from an array of
> pictures?
> The number of pictures varies from 0 to 50.
>
> Is there an easy way to do this?
>
> If I use a {section loop=1} it takes an awful lot of if's to get what i
want
> and i haven't been successfull in using{section loop=3}
>
> Any help would be great :).
>
> / Peter