Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 11th, 2007, 03:24 AM
Authorized User
 
Join Date: Jan 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default looping

hi all and thanks for the support till now, i hope you all guys had a nice vacation.

here is the problem:

i have a table with the following columns:

PID, PName, PPID, Level. P: Property, PPID: ParentpropertyId

now i have the following properties:

human level 1
 man level 2 subcategories
 woman level 2 subcategories
Animals level 1
 cats level 2 subcategories
 dogs level 2 subcategories
plants

the question is that i want to dispaly them like this: property first and then subcategories according to the relative property, for that i create the following queries:

to display the property:

select PName from tblproperty where level = 1

to display the subcategories:

select PNAme from tblproperty where level = 2 and parentpropertyid <> propertyid

in this second query i'm getting all the subcategories.

i created also this 2 for loops:

for i = 0 to counter1
  show property
   for j = 0 to counter2
      show subcategories
    next
next

now i'm getting for everyone all the subcategories even for the ones that did not have subcategories like plants

the output i'm getting now is:

human level 1
 man level 2 subcategories
 woman level 2 subcategories
 cats level 2 subcategories
 dogs level 2 subcategories
Animals level 1
 man level 2 subcategories
 woman level 2 subcategories
 cats level 2 subcategories
 dogs level 2 subcategories
plants
 man level 2 subcategories
 woman level 2 subcategories
 cats level 2 subcategories
 dogs level 2 subcategories

any idea how i can solve this problem?
do i need to change my query or add something to my loop
the parent propertyid is just a column to link the subcategory to propert, so human has PID = 1 level 1 , then man has parentpropertyid = 1 and level = 2

thanks

 
Old September 26th, 2007, 12:21 AM
Authorized User
 
Join Date: Dec 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default


In your Parent Query Add PID field also like this -

select PID,PName from tblproperty where level = 1

And in the Parent Loop use a variable to store value of PID. And in Inner Loop use this query -

select PNAme from tblproperty where parentpropertyid=variable_name_that_holds_parent_q ueries_PID_Value










Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping Code 2 takwirira Excel VBA 0 May 19th, 2008 06:39 AM
Looping ssaranam SQL Server 2005 2 April 17th, 2008 01:40 AM
Looping deepsea007 XSLT 1 June 14th, 2007 12:13 PM
Chapter 9 (Looping) Try It Out melbsurfer BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 January 27th, 2006 01:54 PM
Looping..? dedex C# 2 January 6th, 2005 11:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.