|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
emi226 Smarty n00b
Joined: 06 Aug 2010 Posts: 1
|
Posted: Fri Aug 06, 2010 10:50 pm Post subject: Afficher le resultat d'une requete grace a un boucle. |
|
|
Bonjour !
J'ai une question normalement plutôt simple.
J'ai donc une table dans ma BDD avec 2 colonnes "id_rival" et "id_perso"
Je souhaite récupérer le contenue de la table, l'assigner à smarty pour ensuite afficher une liste grâce à une boucle dans smarty.
REQUETE :
$req = Db::getInstance()->Execute('SELECT * FROM `mtet_perso`');
Dois-je faire un mysql_fetch_array ?
Pourriez vous me faire le code smarty de la boucle qui affiche quelque chose du genre :
<li> id perso : x id_rival : x </li>
<li> id perso : x id_rival : x </li>
<li> id perso : x id_rival : x </li>
Merci beaucoup d'avance !!! |
|
Back to top |
|
Gowser Smarty Pro
Joined: 19 Feb 2008 Posts: 104 Location: Nantes (France)
|
Posted: Mon Aug 23, 2010 6:58 am Post subject: |
|
|
Bonjour,
Il faudrai récupérer le résultat de la requete puis l'envoyer à smarty pour qu'il l'affiche avec un foreach ou un section :
Code: | <?php
/*
RECUPERATION DES DONNEES
*/
// je ne sais pas ce que tu utilises comme adapteur de DB donc je fait a la sauce normale
$result = mysql_query('SELECT * FROM `mtet_perso`');
while($row = mysql_fetch_array($result)){
$tableau[] = $row;
}
/*
ENVOI AU TEMPLATE DE TON RESULTAT
*/
$smarty->assign('tableau', $tableau);
?> |
Code: | <ul>
{section name=indexTableau loop=$tableau}
<li>{$tableau[indexTableau].id_rival} : {$tableau[indexTableau].id_rival}</li>
{/section}
</ul>
ou
<ul>
{foreach from=$tableau item=item key=key}
<li>{$item.id_rival} : {$item.id_rival}</li>
{/foreach}
</ul> |
Cordialement |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|