PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.smarty.general > How to iterate in a table ...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to iterate in a table ...

Réponse
 
LinkBack Outils de la discussion
Vieux 11/02/2006, 15h54   #1
Reynier Perez Mira
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to iterate in a table ...

Hi to every:
I know how to iterate with elements came from array. For example this:
PHP Code:
----
$query = $db->Execute("SELECT * FROM tabla"); // this return at least 10 elements
$ac = array();
while ( $record = $query->fetchRow() ) {
$ac[] = $record;
}
$tpl->assign('ac', $ac);

TPL Code:
---
<table widht="100%" cellpadding="0" cellspacing="1" border="0">
{foreach from=$ac item=element name=it}
<tr>
<td>{$element.ID}</td>
<td>{$element.Name}</td> </tr>
{/foreach}
</table>

This code repeat ten times a row with two columns. Now I need to build a table with two columns but in another way. Mean this:

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Element1</td>
<td>Element2</td>
<td>Element3</td>
</tr>
<tr>
<td>Element4</td>
<td>Element5</td>
<td>Element6</td>
</tr>
<tr>
<td>Element7</td>
<td>Element8</td>
<td>Element9</td>
</tr>
</table>

Understand ?
Best,
--
ReynierPM
4to. Ing. Informática
Linux User: #310201
El programador superhéroe aprende de compartir sus conocimientos. Es el referente de sus compañeros. Todo el mundo va a preguntarle y él, secretamente, lo fomenta porque es así como adquiere su legendaria sabiduría: escuchando ayudando a los demás...
  Réponse avec citation
Vieux 11/02/2006, 16h06   #2
Pedro
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to iterate in a table ...

check out the first, last and index properties, you need something along
the lines of..(psuedo code)

{assign var=cols value=3}
<table>
{foreach from=$ac item=element name=f}
{if $smarty.foreach.f.first}
<tr>
{/if}

{if $smarty.foreach.f.index % $cols ==0}
</tr><tr>
{/if}
<td>{$element}</td>
{/foreach}
</table>

regards

Pete

Reynier Perez Mira wrote:
> Hi to every:
> I know how to iterate with elements came from array. For example this:
> PHP Code:
> ----
> $query = $db->Execute("SELECT * FROM tabla"); // this return at least 10 elements
> $ac = array();
> while ( $record = $query->fetchRow() ) {
> $ac[] = $record;
> }
> $tpl->assign('ac', $ac);
>
> TPL Code:
> ---
> <table widht="100%" cellpadding="0" cellspacing="1" border="0">
> {foreach from=$ac item=element name=it}
> <tr>
> <td>{$element.ID}</td>
> <td>{$element.Name}</td> </tr>
> {/foreach}
> </table>
>
> This code repeat ten times a row with two columns. Now I need to build a table with two columns but in another way. Mean this:
>
> <table width="100%" border="0" cellspacing="0" cellpadding="0">
> <tr>
> <td>Element1</td>
> <td>Element2</td>
> <td>Element3</td>
> </tr>
> <tr>
> <td>Element4</td>
> <td>Element5</td>
> <td>Element6</td>
> </tr>
> <tr>
> <td>Element7</td>
> <td>Element8</td>
> <td>Element9</td>
> </tr>
> </table>
>
> Understand ?
> Best,

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 20h22.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09355 seconds with 10 queries