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

Affichage d'un array à 2 dimensions

 
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
Zemeckis
Smarty n00b


Joined: 18 May 2008
Posts: 2

PostPosted: Sun May 18, 2008 10:13 am    Post subject: Affichage d'un array à 2 dimensions Reply with quote

Salut,

je me suis lancé dans smarty depuis peu et là, je galère pour afficher le contenu d'un array.

index.php
Code:


require('includes/setup.php');
require("includes/classe.accesbase.php");
$smarty = new Site_Smarty();

$acces = new AccesBase;
$retour = $acces->getNews();

$liste_news = array();
$liste_news[] = array();
$i = 0;
while($donnees = mysql_fetch_array($retour))
{
   $liste_news[$i]['id_news'] = $donnees['id_news'];
   $liste_news[$i]['titre_news'] = $donnees['titre_news'];
   $liste_news[$i]['date_news'] = $donnees['date_news'];
   $liste_news[$i]['posteur_news'] = $donnees['posteur_news'];
   $liste_news[$i]['contenu_news'] = $donnees['contenu_news'];
   $liste_news[$i]['lien_image_news'] = $donnees['lien_image_news'];
   $i++;
}

$smarty->assign('liste_news', $liste_news);
$smarty->display('index.tpl');



index.tpl
Code:


<div>

   {foreach key=k item=v from=$liste_news}
   titre : {$v[$k].titre_news}  <br />
   {/foreach}

</div>



Il y a 2 news dans la base, et "titre :" s'affiche 2 fois, donc aucun problème au niveau de la boucle. Mais j'arrive pas à afficher les différentes cases d'une ligne.

Quelqu'un voit le problème ?
Back to top
View user's profile Send private message
Vynka
Smarty Rookie


Joined: 30 Apr 2003
Posts: 17
Location: Belgium

PostPosted: Wed May 21, 2008 8:16 am    Post subject: Reply with quote

Salut,

Je pense que le problème vient de ton affichage dans le template ;
tu confonds, section et foreach, je pense !
Tu n'a pas besoins, dans "foreach" de spécifier l'iterateur.

Essaye peut-être ceci :
Code:
<div>
    {foreach from=$list_news item="v"}
    titre : {$v.titre_news}<br />
    {/foreach}
</div>


Voilà
_________________
Au pays des Gloups!
http://www.wishlist.lu
Back to top
View user's profile Send private message Visit poster's website
Zemeckis
Smarty n00b


Joined: 18 May 2008
Posts: 2

PostPosted: Sat May 24, 2008 4:04 pm    Post subject: Reply with quote

c'était bien ça, merci !
Back to top
View user's profile Send private message
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