Section Loop Problem
| From: | Jon Bertsch | Date: | Thu, 09 May 2002 15:18:34 +0000 |
| Subject: | Section Loop Problem | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-4124@lists.php.net to get a copy of this message | ||
Hi all,
I'm having a problem with section loops and an array. I used an earlier version of Smarty and my previous solution has always worked. I upgraded to Smarty 2.1x for a new project and my old way of looping through an array no longer works.
Please could someone tell me what I'm doing wrong here.
php code:
$query = "SELECT A1_id,Building,FacDept,Year FROM $db_choice WHERE Proj_Num = '$project_number' ORDER BY Building";
$result = mysql_query($query) or die("Error in query");
$building_array = array();
while ($building_array = mysql_fetch_array($result)) {
$building[] = $building_array;
}
mysql_free_result ($result);
$smarty->assign("building","$building");
In my template:
{section name=buildinfo loop=$building}
building:{$building[buildinfo].Building},
id:{$building[buildinfo].A1_id}
Year: {$building[buildinfo].Year},
FacDept: {$building[buildinfo].FacDept}
{/section}
The contents of $building = Array according to the debug consol, but the section loop gives no output.
I can build a list of the data coming out of the query in php by looping through the while statement and assigning each variable such as $building = $building_array["Building"]; so I know that data is available. I'm trying to avoid building an HTML string in my PHP (which I could have completed over an hour ago), to leave the html on the template side.
What am I doing wrong. I'm sure it's something fairly easy, just can't see it right now.
Any help most appreciated.
Thanks
Jon Bertsch