looking for some solutions? You are welcome.

SOLVED: Need help to select and loop a table asp classic

Claes Gustavsson:

I need some help to loop the right way, Im missing something.

I have to select an order from a cart table and then mail a confirmation to the customer with the products and the sale company address from another table.

The problem is that the products in 1 order can come from 2 different companies so I need to first display the products from company 1 and then the address from company 1 and then the products from company 2 and then the address from company 2.

So it need to look like this.

Product 1 Product 2

Company name 1 Address 1 Postcode 1 City 1

Product 3 Product 4

Company name 2 Address 2 Postcode 2 City 2

And this is what I have now.

sql = " SELECT * FROM cart WHERE ordernummer = "&ordernummer&" group by userId"
set rs = conn.Execute (sql)

do until rs.eof
            uId=rs("userId")
            sql7 = " SELECT * FROM cart WHERE userId = "&uId&""
            set rs7 = conn.Execute (sql7)
            do until rs7.eof
                art=art&"<br>"&rs7("artikel")&" "&rs7("pris")&" kr"
            rs7.movenext
            loop

sql3 = " SELECT * FROM users WHERE userId = "&uId&""
            set rs3 = conn.Execute (sql3)
            foretagsnamn=rs3("foretagsnamn")
            adress=rs3("adress")
            postnr=rs3("postnr")
            postadress=rs3("postadress")
            email=rs3("email")
            hamtatext=rs3("hamtatext")
            kartlank=rs3("kartaemaillink")

            companyinfo="<br><br>"&foretagsnamn&"<br>" &_ 
             adress&"<br>" &_ 
             postnr&"<br>" &_ 
             postadress&"<br>" &_ 
             "<a href=mailto:"&email&" style='text-decoration:none;color:#6d6d72;' target='_blank'>"&email&"</a><br>" &_
             "<a href="&kartlank&" target='_blank' style='text-decoration:none;color:#F90;'>Se karta</a><br>" &_ 
             "Du kan nu h&auml;mta dina varor: <span style='color:#F90;'>"& hamtatext &"</span><br><br>"

            companyinfo2=companyinfo2+companyinfo
            companyinfo=""
            art2=art2+art
            art = ""      
     rs.movenext
     loop



     message="<br>"&art2&companyinfo2
    response.write message&"<br>"

And the db looks like this. Where userId is the different companies.

enter image description here

But with this it displays all products and then the company 1 info only. I have tested with so many different variants of this, but I can't get it right. So any input really appreciated, thanks.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent