Réf. : Re: [SMARTY] SQL result array into section
| From: | philippe dot morange at ca-indosuez dot com | Date: | Mon, 10 Feb 2003 08:47:05 +0000 |
| Subject: | Réf. : Re: [SMARTY] SQL result array into section | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-7612@lists.php.net to get a copy of this message | ||
I noticed a problem with Sections when the keys of the array are not in a sequence:
if the keys are not 0, 1, 2, 3, 4, ...
but 0, 1, 3, 4, ...
Three will be a problem at printing.
If you experience this, use foreach instead. But it's a shame section won't work properly
in that
case :-(
Best regards,
Philippe Morange.
markku.niskanen@arctive.com (Markku Niskanen) le 10/02/2003 08:47:07
Pour : smarty-general@lists.php.net
cc : (ccc : Philippe MORANGE/EST/DOSI/BANQUE_INDOSUEZ/FR)
Objet : Re: [SMARTY] SQL result array into section
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
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php