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

Boucles imbriquées

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


Joined: 25 Oct 2008
Posts: 1

PostPosted: Sat Oct 25, 2008 8:35 pm    Post subject: Boucles imbriquées Reply with quote

Salut, je viens vers vous pour m'aider a résoudre un problème

voila j'aimerai afficher des infos du genres

Nom de personne1
Type de la personne1
Type de la personne1

Nom de personne2
Type de la personne2
Type de la personne2

.....

voila mes le pb c'est que apres mon essai je recois les infos comme cela

Nom de personne1
Type de la personne1
Type de la personne1
Type de la personne2
Type de la personne2

Nom de personne2
Type de la personne1
Type de la personne1
Type de la personne2
Type de la personne2

c'est naze hen Crying or Very sad :p

voila mes codes



Code:

<?php
   
   include('libs/Smarty.class.php');
   $oSmarty = new Smarty();
   // Le tableau conteneur des éléments RSS
   $personnes = array();   
   $types = array();   
   // Se connecter à mysql
   if (! $oConnexion = mysql_connect('localhost', 'root', ''))
      die("Impossible de se connecter");
   // Choisir la base de données   
   if (! mysql_select_db('testsmarty'))
         die("Erreur de selection de la base de données");
   // Construire la requête
   $sSql = "SELECT * FROM client, type, client_type WHERE client.id_client=client_type.id_client AND client_type.id_type=type.id_type GROUP BY client.id_client" ;
   // Exécuter la requête et récupérer le jeu d'enregistrements
   if (! $oMysqlRes = mysql_query($sSql))
      die("Erreur: la requête n'a pu être exécutée");
   
   // Pour chaque ligne du jeu d'enregistrement
   while ($oRow = mysql_fetch_array($oMysqlRes)) {
      // Ajouter dans le conteneur
         $resultat1 = "SELECT type.libelle FROM client, type, client_type WHERE client.id_client=client_type.id_client AND client_type.id_type=type.id_type and client.id_client= '".$oRow['id_client']."' GROUP BY type.id_type";
         $mysql_rs = mysql_query($resultat1) or die(mysql_error());      
            
            if (! $mysql_rs = mysql_query($resultat1))
               die("Erreur: la requête n'a pu être exécutée");

         while ($aRow = mysql_fetch_array($mysql_rs)) {
            array_push($types, $aRow);
         }
      array_push($personnes, $oRow);
   }   
   $oSmarty->assign('personnes', $personnes);
   $oSmarty->assign('types', $types);
   //header("Content-Type: text/xml");   
   $oSmarty->display('rss.tpl')
?>


Code:

{section name=itemIndex loop=$personnes}     
   <Personne>{$personnes[itemIndex].nom} {$personnes[itemIndex].prenom}</Personne>
   <types>
      {section name=id loop=$types}
         {$types[id].libelle}
      {/section}
         - {$personnes[itemIndex].age}ans
   </types>
{/section}


si des gens penvent m'aider ce serai cool Rolling Eyes
Back to top
View user's profile Send private message
wartin16
Smarty n00b


Joined: 23 Oct 2008
Posts: 3

PostPosted: Tue Oct 28, 2008 9:37 pm    Post subject: Reply with quote

Hello

eh bien dans ton code php tu pourrais utiliser un tableau à deux dimensions.

Parce que là, le retour est normal! Tu as tous tes types dans un même tableau que tu parcours avec smarty.

$personne[index]['nom'] -> nom de la personne

$personne[index]['type'] -> tableau de type correspondant à la personne
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