Re: [SMARTY] SQL result array into section

From: Date: Mon, 10 Feb 2003 07:47:07 +0000
Subject: Re: [SMARTY] SQL result array into section
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-7611@lists.php.net to get a copy of this message
On Sun, 9 Feb 2003 11:38:03 +0200, you wrote: >I have a general SQL query class, which returns rows like this (I'm >sending it to smarty with name $tablerows): >Array ( [0] => Array ( [0] => Timo [1] => Railo [2] => 0505002232 [3] >=> Tester ) > [1] => Array ( [0] => poni [1] => puikkonen [2] => 012012012 >[3] =>)) >But I just can't get the inner section constructed properly. I've seen Here's an utterly simplified example that produces an HTML table from any query, being totally generic. {* the template nestedsections.tpl *} <html> <body> <table border=1> {section name=outer loop=$tablerows} <tr> {section name=inner loop=$tablerows[outer]} <td>{$tablerows[outer][inner]}</td> {/section} </tr> {/section} </table> </body> </html> And the corresponding PHP code <?php include("smarty.inc"); // settings,create $smarty object... $server= "localhost"; $db = "testi"; $user = "markku"; $pw= "markku"; $connection = mysql_connect($server,$user,$pw); $handle= mysql_select_db($db) or die ("Oh yeah..."); $query = "select * from customer"; $result = mysql_query($query) or die("Oh no!"); while ($row=mysql_fetch_row($result)){ $tablerows[] =$row; } $smarty->assign("tablerows",$tablerows); $smarty->display("nestedsections.tpl"); ?> Hope this helps anybody with similar problems. -- Arctive Oy Markku Niskanen GSM 045 - 6733 543 Arctive Oy, Länsikatu 15, 80110 JOENSUU http://www.arctive.com

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