[SMARTY] Re: Nested queries/nested arrays

Gary Smith <[email protected]>
Newsgroups gmane.comp.php.smarty.general
Message-ID <BF2109EF.558D7%[email protected]>
Hi Amanda,

I'm no expert but I think if you

change this:
$query ="SELECT * FROM projects WHERE parent_project_id =
$projects[$key]['project_id']";
to this
$id = $projects['parent_project_id'];
$query ="SELECT * FROM projects WHERE parent_project_id = ? ";

And this:
$sub = $db->getAssoc($query, DB_FETCHMODE_ASSOC);
to this
$sub = $db->getAssoc($query, array($id));

It might work. 

Thanks to Matthew Weier O'Phinney
Gary
 


in article [email protected], Amanda Hemmerich at
[email protected] wrote on 8/11/05 8:27 AM:

> Hello!
> 
> I'm using PHP and Smarty to try to build an array of arrays using the
> results from nested queries.  I am just learning about nested arrays,
> and I'm not sure what I'm doing wrong.
> 
> I am hoping someone can give me a hint as to what I am doing wrong.
> 
> If I remove the PHP foreach loop, it works fine, except, of course, no
> sub projects show up.  :)  The error must be in there, but I'm just not
> seeing it.
> 
> I get the following error with the code below:
>    
> Warning: Smarty error: unable to read resource: "welcome/Object.tpl" in
> /usr/local/lib/php/Smarty/Smarty.class.php on line 1088
>  
> PHP STUFF
> $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) {
> $query ="SELECT * FROM projects WHERE parent_project_id =
> $projects[$key]['project_id']";
> $sub = $db->getAssoc($query, DB_FETCHMODE_ASSOC);
> $projects[$key]['subs'] = $sub;
> }
> $tpl->assign('projects', $projects);
>  
> SMARTY STUFF
> {foreach from=$projects item='entry'}
>   <b>{$entry.short_name}</b><br />
>   <ul>
>   {foreach from=$entry.subs item='sub'}
>       <li>{$sub.short_name}</li>
>   {foreachelse}
>       <li>No subs for this project</li>
>   {/foreach}
>   </ul>
> {foreachelse}
>   <b>No projects found</b>
> {/foreach}
> 
> Can anyone point me in the right direction?
> 
> Thanks,
> Amanda

-- 
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.