RE: [SMARTY] Smarty, PEAR, Associative Array and Loops

From: Date: Wed, 06 Apr 2005 14:15:09 +0000
Subject: RE: [SMARTY] Smarty, PEAR, Associative Array and Loops
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12421@lists.php.net to get a copy of this message
Hi Im not 100% sure of what is your goal but i guess you want to do something like this ;) ... $row = $database->getAll('SELECT * FROM eventos', null, DB_FETCHMODE_ASSOC); $template->assign("eventList",$row); {section name=titulo loop=$titArr name=eventos} {foreach from=$eventList item=event} <tr> <td width="3%" valign="top" class="tddoted" align="center"> <strong>{$smarty.foreach.eventos.rownum}.</strong></td> <td width="97%" class="padding-td tddoted"> {$event.titulo}</td> </tr> <tr> <td width="3%" valign="top" class="tddoted" align="center"> <strong>&nbsp;</strong></td> <td width="97%" class="padding-td tddoted"> {$event.descripcion}</td> </tr> {/foreach} Regards -----Message d'origine----- De : Reynier Pérez Mira [mailto:reynierpm@yahoo.es] Envoyé : 5 avril 2005 23:46 À : Smarty Objet : [SMARTY] Smarty, PEAR, Associative Array and Loops Well again I came to experts to help me. The situation is this. I use PEAR DB on my pages and Smarty as Templates Enginee. First I have this table: CREATE TABLE eventos ( id int(11) unsigned NOT NULL auto_increment, titulo varchar(200) NOT NULL, descripcion varchar(250) NOT NULL, contenido longtext NOT NULL, PRIMARY KEY (id), UNIQUE KEY id (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; look that the table have more than one field. Second I have this piece of code: $titulo = array(); $descripcion = array(); $contenido = array(); $evenres = $database->query('SELECT * FROM eventos'); while($row = $evenres->fetchRow()){ array_push($titulo,$row[1]); array_push($descripcion,$row[2]); array_push($contenido,$row[3]); $template->assign("titArr",$titulo); $template->assign("descArr",$contenido); $template->assign("conArr",$descripcion); } as you can see I assign var to var to arrays $titulo, $descripcion and $contenido because I not know how to assign all content have $row[] array return from previous query. And last I have this code in my .tpl file: {section name=titulo loop=$titArr} <tr> <td width="3%" valign="top" class="tddoted" align="center"><strong>{$smarty.section.eventos.rownum}.</strong></td> <td width="97%" class="padding-td tddoted">{$evenArr[eventos]}</td> </tr> {section name=descripcion loop=$descArr} <tr> <td width="3%" valign="top" class="tddoted" align="center"><strong>&nbsp;</strong></td> <td width="97%" class="padding-td tddoted">{$descArr[descripcion]}</td> </tr> {/section} {/section} because I not know how to iterate using section function in this case, I mean in the case that the section I try to iterate contain more than one objetcs. I read about use of associatives array whit smarty in help file. Take a look to the material that I found: {* Este es un ejemplo que muestra los datos de una matriz asociativa dentro de una section *} {section name=customer loop=$contacts} name: {$contacts[customer].name}<br> home: {$contacts[customer].home}<br> cell: {$contacts[customer].cell}<br> e-mail: {$contacts[customer].email}<p> {/section} SALIDA: name: John Smith<br> home: 555-555-5555<br> cell: 555-555-5555<br> e-mail: john@mydomain.com<p> name: Jack Jones<br> home phone: 555-555-5555<br> cell phone: 555-555-5555<br> e-mail: jack@mydomain.com<p> name: Jane Munson<br> home phone: 555-555-5555<br> cell phone: 555-555-5555<br> e-mail: jane@mydomain.com<p> but I not know how they return elements, I mean where values came, what's is the PHP code to see the way in they returns values? Since now Regards Reynier Pérez MiraBlog de ReynierPM ______________________________________________ Renovamos el Correo Yahoo!: ¡250 MB GRATIS! Nuevos servicios, más seguridad http://correo.yahoo.es -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#12421) next »