|
Posted by Gary Smith on 08/13/05 04:26
Amanda,
What happens if you
print_r($projects);
after
$tpl->assign('projects', $projects);?
Gary
in article 42FD4781.4010107@indiana.edu, Amanda Hemmerich at
ahemmeri@indiana.edu 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 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);
>>>
>>>
>>
>>
>>
Navigation:
[Reply to this message]
|