Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. 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 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 11th, 2003, 06:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listing Category then Items

Can somebody please give me some advise on how to implement this, I can do the easy SQL statements, but I get lost on the complex ones and what I've tried doesn't work or I know there is a better way, I just don't know it. I am using ASP, SQL Server. Right now I have one table where I want to select all the Categories and Items and have them display as in my sample, without the categories repeating.

SELECT Category, Item FROM Table1 WHERE Start_Date <= '" & Date & "';

This is how I would like it to display
    Category_01
        Item_01
        Item_02

    Category_02
        Item_01
        Item_02
        Item_03
        Item_04

Can this work with one table or should I make another table then select the category and do some kind of Join statement, also some Categories might not have any Items for that day.

Any help would be appreciated, Thanks in advance.
__________________
Peace
Mike
http://www.eclecticpixel.com
Reply With Quote
  #2 (permalink)  
Old December 12th, 2003, 05:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok, so you've got the category and item in the same recordset. Your SQL is fine, you need to do the grouping in your asp code. You just need to keep track of the category as you loop through the recordset and only output the category when it changes, something like this:
Code:
sCatPrevious = ""
Do While Not rs.EOF

  sCatCurrent = "" & rs.Fields("Category").Value
  If sCatCurrent <> sCatPrevious Then
    ' output the category
    Response.Write sCatCurrent

    ' update the "previous" variable
    sCatPrevious = sCatCurrent

  End If

  ' output the item
  Response.Write "" & rs.Fields("Item").Value

  rs.MoveNext
Loop
Reply With Quote
  #3 (permalink)  
Old December 12th, 2003, 05:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Just noticed that you need an ORDER BY clause in your SQL to ensure that the Categories are sorted in your recordset
Code:
"SELECT Category, Item FROM Table1 WHERE Start_Date <= '" & Date & "' ORDER BY Category, Item";
Reply With Quote
  #4 (permalink)  
Old December 12th, 2003, 10:47 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a million. You saved me a lot of time.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing 8-10 and Listing 8-16. Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 February 6th, 2008 12:11 PM
dropdownlist with heading for each category debjanib ASP.NET 2.0 Basics 5 May 16th, 2007 04:19 PM
Add category on Blog highspeedwire BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 January 26th, 2007 04:35 PM
Need help with creating a Parent Category seanmayhew BOOK: ASP.NET Website Programming Problem-Design-Solution 2 November 13th, 2004 05:20 PM
Listing and limiting items from a database RPG SEARCH ASP.NET 1.0 and 1.1 Basics 11 August 3rd, 2004 04:37 PM



All times are GMT -4. The time now is 12:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.