Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Afficher le resultat d'une requete grace a un boucle.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: French
View previous topic :: View next topic  
Author Message
emi226
Smarty n00b


Joined: 06 Aug 2010
Posts: 1

PostPosted: Fri Aug 06, 2010 10:50 pm    Post subject: Afficher le resultat d'une requete grace a un boucle. Reply with quote

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
View user's profile Send private message
Gowser
Smarty Pro


Joined: 19 Feb 2008
Posts: 104
Location: Nantes (France)

PostPosted: Mon Aug 23, 2010 6:58 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: French All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP