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

Cicli foreach annidati sia in php che smarty

 
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: Italian
View previous topic :: View next topic  
Author Message
timgno
Smarty Rookie


Joined: 12 Apr 2013
Posts: 6

PostPosted: Fri Apr 12, 2013 4:29 pm    Post subject: Cicli foreach annidati sia in php che smarty Reply with quote

Ciao!

Ho un problema con dei cicli annidati che non danno il risultato sperato.

Vi mostro un esempio per farvi capire...

PHP:
Code:
foreach (array_keys($array) as $i)
         {            
            $arr['id'] = $i;            
                                $arr['name'] = $array[$i]->getVar('name');                                    
            $smarty->append('arr_list', $arr);            
                                unset($arr);
            // Get the list of tables
            $criteria = new Criteria();
                                // Database table results
            $criteria->add(new Criteria('table_arr', $i));
            
            $tables_arr = $tablesHandler->getAll($criteria);
            unset($criteria);
            // Display tables list               
            foreach (array_keys($tables_arr) as $t)
            {   
                  $table['id'] = $t;
                  $table['aid'] = $tables_arr[$t]->getVar('table_aid');         $smarty->assign('table', $table);            
                   unset($table);               
            }                                       
}


Smarty:
Code:
<{foreach item=arr from=$arr_list}>
         <tr class="head">
       <td class='center'><{$arr.id}></td>
            <td class='center'><{$arr.name}></td>
         </tr>
         <{foreach item=table from=$table}>
             <tr class="center">
               <td class='center'><{$table.id}></td>
                <td class='center'><{$table.name}></td>
             </tr>
         <{/foreach}>
     <{/foreach}>


Ecco questo codice non da il risultato che dovrei avere in base al primo ciclo che è quello principale.

In pratica devo avere come risultato il loop padre con un certo numero di figli nel suo specifico ciclo in base ai risultati del database in questo caso le tabelle. Per ogni array devo avere il suo numero specifico di tabelle.

Ho provato anche con section ma non funziona lo stesso.

Principalmente questo funzionava regolarmente perché non utilizzavo smarty con i template, ma bensì inserivo tutto il linguaggio html insieme al php e quindi utilizzavo solo i due cicli foreach del php.

Spero di trovare in voi un giusto aiuto.

Grazie!
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: Italian 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