[ic] How can I nest loops or queries?

chaim klar hershey135@hotmail.com
Sun, 25 Feb 2001 17:59:15


How can I nest loops or queries?
I have two tables  the first table called products looks like this:
p_sku	price	...,
C2100Z	14.50
C211Z	45.35
KF800	63.98
KW	51.21
KFP	45.92
KFW	51.62
...	....

Then another table called accessories that looks like this:
AutoNumber      a_code  accessory
1       KF800   C2100Z
2       KF800   C211Z
3       KF800   KW
4       KF800   KFP
5       KF800   KFW
6       C2100Z  MBSM
7       C2100Z  16MBSM
8       C2100Z  32MBSM
9       C2100Z  64MBSM
10      C2100Z  B28

(a_code may exist a few for each item in the products table)

So in the flypage.html I first look up in the accessories table with the 
current
item to see if it has  accessories (and to convince myself that it indeed 
have
accessories for the current item I first display them) and then with the 
results
I make another loop in the products table to get the price and description 
for the
accessories like this:

[loop prefix=outer 
search="tf=accessory/ra=yes/fi=accessories/se=[item-code]/sf=a_code/co=yes"]

	[outer-data accessories a_code][outer-data accessories accessory]

	[loop prefix=inner search="fi=products/se[outer-data accessories 
accessory]/co=yes/sf=p_sku/st=db"]
		[inner-data products p_sku][inner-data products price]

	[/loop]
[/loop]


but for some reason I get the accessories to display before entering the 
second loop but not
after the second loop so I have tired doing it with [query] like this:

[query
            st=db
            list=1
            sql=|

                            SELECT p_sku
                            FROM products
                            WHERE p_sku IN (
                                            SELECT accessory
                                            FROM accessories
                                            WHERE a_code = 'KF800'
                                            )
                |
]
    [sql-increment]) [sql-param p_sku]<br>
[/query]

but I didn't get better results.

Thanking You in advance.

Chaim Klar
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com