Code Snippet was: [SMARTY] To who's right is right??

From: Date: Tue, 18 Jun 2002 17:30:26 +0000
Subject: Code Snippet was: [SMARTY] To who's right is right??
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-4927@lists.php.net to get a copy of this message
Well, I had to mess around with multidimensional arrays for a bit to get it working correctly. If anyone is collecting code snippets, then I submit this, else let it sit in the archive... <?php /* Multidimensional array database/smarty code snippet */ require_once('Smarty.class.php'); $tpl = new Smarty; $data = array(); $sql = 'SELECT id, name FROM user_table WHERE id != '0' LIMIT 5'; $result = mysql_query($sql); while ($query_data = mysql_fetch_row($result)) { $data[] = array('id' => $query_data[0], 'name' => $query_data[1]); } $tpl->assign('data', $data); $tpl->display('nice_file.tpl'); $tpl->clear_all_assign(); ?> ------------------ {* nice_file.tpl *} <html> <head> <title>nice_file</title> </head> <body> {* There is nothing like a simple foreach loop *} {foreach item=data from=$data} The user {$data.name} id is ==> {$data.id}<br> {/foreach} </body> </html> Peter Bowyer wrote:
At 06:38 18/06/02 -0400, SP wrote:
People learn by copying so I think smarty should come with a demo of a real application like a form or something.
We keep on discussing this, but no-one's had the time to write anything of the sort yet :-( Peter -- Maple Design - quality web design and programming http://www.mapledesign.co.uk
-- Gerard Samuel http://www.trini0.org:81/ http://dev.trini0.org:81/

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