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

Gary Smith <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <BF22702E.55934%[email protected]>
Amanda,

What happens if you
print_r($projects);
after
$tpl->assign('projects', $projects);?

Gary


in article [email protected], Amanda Hemmerich at
[email protected] wrote on 8/12/05 3:06 PM:

> 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 [email protected], Amanda Hemmerich at
>> [email protected] 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);
>>>    
>>> 
>> 
>>  
>> 

-- 
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.