Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old March 4th, 2004, 05:16 PM
Registered User
 
Join Date: Mar 2004
Location: Houston, Texas, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to plasma800
Default Kinda complicated loop through DB Recordset...

Someone.. PLEASE HELP...

Here's the situation. I have a sql db full of product info. Each product has a slew of info about, one particular property being its "Category".

What Im trying to do is build a page that selects everything from my product table that matches a certain brand and then display the different categories of this brand over a couple of tables.

Lets say the brand is KXT and the categories are Phone, KSU, Card
So after the SQl connect, I select * from the table where brand matches KXT and that works fine.

Now for the loop part. I need the table to be 2 td's per row, and bascially I'm sliding the part number in the table then building a link around it that goes to a "product page" along with the id of the part, that page just then loads the prod info. Ive done these links by hand for a long time, but id really love these lists of parts to come out of the db so I can just manage that and not the pages.

So I tried lots of things
But basically i need to be like so...
do until objRs.eof
 if (obj.Rs("Category") = "Phone") then
   'write these table rows
 end if


and then later down the page, I need to do the same for the next category and then the next so forth and so on, and I would like the table building part to be a sub routine so i can just use it over and over.

<%
Response.Write "<table width=""100%"">" & vbcrlf
Do until objRs.EOF
  if (objRs("Category") = "Phone") then
    Response.Write "<tr bgcolor=""#F4F4F4""><td width=""50%""><a href=""/kxt_product.asp?ProdId=" & objRs("ProdID") & """>" & objRs("ProdSKU") & "</a></td>" & vbcrlf
   objRs.MoveNext
      if objRs.EOF then
        response.write "<td width=""50%""></td></tr>"
      else
        Response.Write "<td width=""50%""><a href=""/kxt_product.asp?ProdId=" & objRs("ProdID") & """>" & objRs("ProdSKU") & "</a></td></tr>"
     objRs.MoveNext
     end if
Response.Write "</table>"
else
response.write "<tr><td>No Data Found</td></tr></table>"
end if
loop
%>

this obviusly does not work though...
I dont know how to handle the two td's. can someone please steer me in the right direction.. cause im lost.

in case anyone cares, this is my connect stuff at the top of the page.

<%
ConnectSQL
Dim objRs, brand
Set objRs = Server.CreateObject("ADODB.Recordset")
objRs.Open "SELECT * FROM bProducts where Brand='14' ORDER BY ProdSKU",objCn, 1, 3
%>

  #2 (permalink)  
Old March 4th, 2004, 05:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When I have done something like this, I have made sure my select statement has been ordered by the category so it groups them together.

I would then loop through them. Before starting the loop (which I would have in the If then statement), I would set the first category name into a variable. Then inside the loop very first, test to see if the new record category matches the variable (which holds the category from the previous table). If so, write out some end of table tags and some start of table tags for the next group, write headers for the table, etc.

Here is an example:

<%
Dim strCategory, rs

'(Open your connection and call it "Conn" for the example)

Set rs = Conn.Execute("SELECT * FROM table ORDER BY CategoryName")
%>

<TABLE BORDER=1>
<%
If not rs.EOF Then
    strCategory = rs("CategoryName").Value
    Do while not rs.EOF
        If strCategory <> rs("CategoryName").Value Then
            response.write("</TABLE><BR>"
            response.write("<TABLE BORDER=1>"
        End If

        'Write out your records for this group

        strCategory = rs("CategoryName").Value
        rs.Movenext
    Loop
End If
%>
</TABLE>

'''END EXAMPLE

This will loop though the whole table and will use existing Database categories, so as the database changes, so does the web page without you maintaining the page at all.

Chris
  #3 (permalink)  
Old March 4th, 2004, 06:23 PM
Registered User
 
Join Date: Mar 2004
Location: Houston, Texas, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to plasma800
Default

ic... ic... thanks chris!!!



Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through 17 tables in RecordSet object didimichael C# 1 July 18th, 2008 06:53 AM
recordset not showing up on page loop pablohoney Classic ASP Databases 1 December 14th, 2005 06:43 PM
Querying Recordset with a Loop rabu Access VBA 10 December 14th, 2005 04:49 PM
Filter recordset in loop Freddyfred Access 1 February 15th, 2005 09:09 AM





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