You are here: Re: [SMARTY] multiple nested queries? « Smarty Templates Posts « IT news, forums, messages
Re: [SMARTY] multiple nested queries?

Posted by Cameron Perry on 09/30/00 11:23

The key is to write it into the same array, and keep track of which
element is a top-level or sub-level item. You could achieve this with
a while loop pretty easily, as long as you know the maximum depth of
your tree. You could structure the array like this:

$item[$idx]['name']
$item[$idx]['id']
$item[$idx]['level'] //top- or sub-level
$item[$idx]['link']

.... and your (pseudo)code:
$sql="SELECT * FROM main";
$result=mysql_query($sql);
while($mainRow=mysql_fetch_assoc($result))
{
//write $mainRow elements to $item array
//$idx++;

$sql_sub="SELECT * FROM tabletwo where id=$mainRow[id]";
$result_sub=mysql_query($sql_sub);
if(mysql_num_rows($result_sub)>0)
{
while($subRow=mysql_fetch_assoc($result_sub))
{
//write $subRow elements to $item array
//$idx++;
}
}
}
....you get the idea

Once you have this array built you can stick it all into smarty as
you normally do, but using your $item results instead.

HTH,
Cameron

On Aug 8, 2005, at 12:24 PM, Amanda Hemmerich wrote:

> Hello! I'm pretty new to PHP and Smarty.
>
> I am trying to build a dynamic navigation bar using mysql, PHP, and
> smarty. I need to get the name and id of each menu item and then
> for each item, query a different table and get the sub-items
> associated with them.
> My normal way of using queries is to query the database and loop
> through the result with a smarty section and display the results.
> Is there a way I can loop through the results and build another
> query and then loop through THOSE results, too?
>
> Thanks,
> Amanda
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

 

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

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