more on array index variables
| From: | Phillip Smith | Date: | Mon, 13 May 2002 18:50:47 +0000 |
| Subject: | more on array index variables | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-4180@lists.php.net to get a copy of this message | ||
So my previous problem was solved when I was simply dealing with
individual variables. Now I would like to just pass in the entire array,
and be able to access individual fields (or loop over all fields).
I've tried this several different ways, but I'm uncertain the proper
syntax for referencing the array. The Smarty docs don't seem to go into a
whole lot of detail with this. Anyway, here's what I'm doing:
index.php:
$dsn =
$db_type.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name;
$db = DB::connect($dsn);
$sql = "SELECT * FROM events ORDER BY date DESC ";
$events = $db->getAll($sql);;
$tpl->assign("events",$events);
// set from url
$tpl->assign("id",$id);
$tpl->display("events.tpl");
events.tpl:
{if $id eq ""}
{section name =id loop=$events}
{* argh! which one is correct? *}
{$events[id].type}<br>
{$events.type[id]}<br>
{$events[id].type[id]}<br>
{$events.type.id}<br>
{/section}
{else}
{$events.type.$id} or {$events.$id.type} or {$events[$id].type}
{/if}
Maybe it's my SQL query, but there is data in $events (if I put something
in the first one such as a - so there is a character displayed, it will
loop as many times as there are rows in the db)
I'd appreciate suggestions on how to properly do this.
Thanks.
-phillip