Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL problem I think
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL problem I think

 Post Reply Post Reply
Author
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Topic: SQL problem I think
    Posted: 08 January 2004 at 2:54am
The problem I am facing is I can only see one product category only. It should be a product category, a list of companies inside it, then another product category, another list of companies inside it. Now is one product category, then all the list of companies.

All help is appreciated.

    <%      & nbsp;  
   sql = "SELECT * FROM productcat ORDER BY productcat"
   rs.CursorLocation = 3   
   rs.open sql, conn
      
   if not rs.eof then
    do while not rs.eof
    response.write "<tr><td>Product Category: " & rs("productcat") & "</td></tr>"
        
    set rs2 = Server.CreateObject("ADODB.recordset")
    set sql2 = Server.CreateObject("ADODB.command")    
         
    sql2 = "Select * FROM customer as c, cust_productcat as cpc, ProductCat as pc "
    sql2 = sql2 & "WHERE cpc.ProductCatID = " & rs("productcatid") & " "
    sql2 = sql2 & "AND cpc.ProductCatID = pc.ProductCatID "
    sql2 = sql2 & "AND cpc.CompanyID = c.CustID "           ;           ;           ;           ;           ;           ;           ;       
    sql2 = sql2 & "ORDER BY c.companyname"       &nbs p; 
    rs2.CursorLocation = 3
    rs2.open sql2, conn         &n bsp;    
                                                           
    if not rs2.eof then
     Do While Not rs2.EOF          ;       
      if rs2("listing") = "Yes" then
       response.write "<tr><td><br>" & rs2("companyname") & " *</td></tr>"
      else
       response.write "<tr><td><br>" & rs2("companyname") & "</td></tr>"
      end if     
      rs2.MOVENEXT
     LOOP
    END IF
    rs2.close
    set rs2 = nothing
   rs.movenext
   loop
   end if         
   %>      


Edited by ngaisteve1
Back to Top
aalavar View Drop Down
Groupie
Groupie


Joined: 08 December 2003
Status: Offline
Points: 46
Post Options Post Options   Thanks (0) Thanks(0)   Quote aalavar Quote  Post ReplyReply Direct Link To This Post Posted: 08 January 2004 at 8:10am
If you get rid of the loop that goes through all the companies, does it display all of your product categories?  Or are you saying that it displays a product category, all the companies, then another product category, then all of the companies again?
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 08 January 2004 at 9:35am

I have found nested recordset to be very unreliable, they do work but often cause problems. If you have hierarchical data and would like to display it that way have a look at ADO Data Shaping which will take care of it. There are a bunch of tutorials if you do a search on google or so.

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2004 at 11:05am

why do you have this line?

set sql2 = Server.CreateObject("ADODB.command")    

after that line, "sql2" is a string containing a SQL statement

Contribute to the working anarchy we fondly call the Internet
Back to Top
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2004 at 8:47pm
I have changed sql2 to sql but still the same result.
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2004 at 8:56pm
Try putting the creation of the recordset object outside the loop, and also the dropping of the object outside the loop.  Had a simliar problem, this seemed to be the problem.
Back to Top
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Posted: 09 January 2004 at 8:59pm
Alright, I got it actually, just couldn't see, 'hidden' under one of the records coz didn't have line spacing. I only found it using Ctrl + F. Thanks.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.