[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
Re: [ic] How can I nest loops or queries?
At 05:59 PM 2/25/2001 +0000, chaim klar wrote:
>How can I nest loops or queries?
Does this help?
Taken from recent post by Mike Heins:
http://developer.akopia.com/archive/interchange-users/2001/msg01564.html
Quoting Dan B (db@cyclonehq.dnsalias.net):
> Solved it, works perfect. :-) Thanks to Christopher F. Miller and the
> mailing list archive. Hopefully this will come in handy to the next person
> searching the archives.
>
And though I jumped in late, there actually isn't any reason you can't nest a
query. I don't know why I never remembered to remove the "canNest" check for
Tagref.pm, but that is actually a legacy from the less-capable MV3 parser.
This nested query:
[query list=1 prefix=outer sql="select category from products"]
[query
list=1 prefix=inner
sql="
SELECT sku,description
FROM products
WHERE category = '[outer-code]'
"][outer-code] : [inner-code] : [inner-param description]<BR>
[/query]
[/query]
seems to work fine. Of course you have to have separate prefix= things
so the placeholders get substituted correctly, but it will work. As will
a loop in a loop, etc. Not the best way to get great performance, though. 8-)
--
Red Hat, Inc., 131 Willow Lane, Floor 2, Oxford, OH 45056
phone +1.513.523.7621 fax 7501 <mheins@redhat.com>
Experience is what allows you to recognize a mistake the second
time you make it. -- unknown
>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
>
>
>_______________________________________________
>Interchange-users mailing list
>Interchange-users@lists.akopia.com
>http://lists.akopia.com/mailman/listinfo/interchange-users
Dan Browning, Cyclone Computer Systems, danb@cyclonecomputers.com
_______________________________________________
Interchange-users mailing list
Interchange-users@lists.akopia.com
http://lists.akopia.com/mailman/listinfo/interchange-users