You are here: Re: Nested queries/nested arrays « Smarty Templates Posts « IT news, forums, messages
Re: Nested queries/nested arrays

Posted by Gary Smith on 08/12/05 05:25

Hi Amanda,

It looks like your looking for empty parent_project_id's which would mean
there is no parent_project_id in the results of the first query.

$query ="SELECT * FROM projects WHERE parent_project_id is NULL OR
parent_project_id = ''";

> The above should be:
> $id = $projects[$key]['parent_project_id'];

I think it should be
$id = $projects[$key]['project_id'];
Since parent_project_id would be empty.


Matthew, thanks for your help on my post. I'm using adodb so I had to remove
the force (boolean) parameter. I'm new to adodb and your sample code was
very helpful and educational. It seems to be a lot more powerful then phplib
which I'm moving away from.

> I think the problem causing the notice the OP is receiving is more
> likely to do with file location and/or permissions, and I've responded
> to that under separate cover. However, the above is definitely an issue
> as well.

Yeah, welcome/Object.tpl seems to be causing a problem.

Gary



in article slrndfnthe.qdf.mweierophinney@ubergeek.garden.org, Matthew Weier
O'Phinney at mweierophinney@gmail.com wrote on 8/11/05 3:07 PM:

> * Gary Smith <gts@tsu.biz> :
>> 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'];
>
> The above should be:
> $id = $projects[$key]['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));
>
> getAssoc(), in PEAR::DB at least expects
> ($sql (string), force (boolean), parameters (array)) as its arguments:
>
> $sub = $db-> getAssoc($query, false, array($id));
>
>> Thanks to Matthew Weier O'Phinney
>
> Thanks.... I think... :-)
>
> I think the problem causing the notice the OP is receiving is more
> likely to do with file location and/or permissions, and I've responded
> to that under separate cover. However, the above is definitely an issue
> as well.
>
>> in article 42FB988A.8030002@indiana.edu, Amanda Hemmerich at
>> ahemmeri@indiana.edu 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?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация