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
%>
|