Re: [SMARTY] Re: Nested queries/nested arrays

From: Date: Sat, 13 Aug 2005 01:06:09 +0000
Subject: Re: [SMARTY] Re: Nested queries/nested arrays
References: 1 2 3 4 5  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12956@lists.php.net to get a copy of this message
Great! That worked! At least, it didn't get any errors. :) Now, I am trying to loop through both arrays on the HTML/Smarty side, but nothing is showing up. The name of the project does not show up, but for each iteration of the loop, it prints out "- id ()" and "No subs for this project", even for projects that have sub projects. I've never used a Smarty "foreach" before - I normally use Smarty "sections", and I'm not getting any errors, so I'm not sure what I'm doing wrong. {foreach from=$projects item='entry'} <b>{$entry.short_name}</b> - id ({$entry.project_id})<br /> <ul> {foreach from=$entry.subs item='sub'}
       <li>{$sub.short_name} - {$sub.project_id}</li>
{foreachelse}
       <li>No subs for this project</li>
{/foreach} </ul> {foreachelse} <b>No projects found</b> {/foreach} Gary Smith wrote:
Hi Amanda, Try this: $query ="SELECT * FROM projects WHERE parent_project_id is NULL OR parent_project_id = ''"; $projects = $db->getAssoc($query, DB_FETCHMODE_ASSOC); foreach ($projects as $key => $project) { if (!empty($project['project_id'])){ $id = $project['project_id']; $query ="SELECT * FROM projects WHERE project_id = ? "; $sub = $db->getAssoc($query, false, array($id)); $projects[$key]['subs'] = $sub; } } $tpl->assign('projects', $projects); Gary in article 42FCF52F.9040707@indiana.edu, Amanda Hemmerich at ahemmeri@indiana.edu wrote on 8/12/05 9:14 AM:
$query ="SELECT * FROM projects WHERE parent_project_id is NULL OR parent_project_id = ''"; $projects = $db->getAssoc($query, DB_FETCHMODE_ASSOC); foreach ($projects as $key => $project) { if (!empty($project[$key]['project_id'])){ $id = $project[$key]['project_id']; $query ="SELECT * FROM projects WHERE parent_project_id = ? "; //$sub = $db-> getAssoc($query, false, array($id)); //$projects[$key]['subs'] = $sub; } } $tpl->assign('projects', $projects);


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