Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question how to loop through 2 of same products?

    ok, in my shop database, if someone buys 2 (or more) of the same product it then shows in QTY field as 2 or however many they have bought.

    how do i write out(loop through) the products that are duplicated?

    my code is below:

    Code:
    <%Dim decodeOfficeType, objField, GetStatus%>
    <%
    Set rs = Server.CreateObject("ADODB.Recordset")
    OrderNumber = request.querystring("ONumber")
    rs.ActiveConnection = MM_CON_Database_STRING
    rs.source = "SELECT tblCustomerRecords.*, tblCustomerOrders.* FROM tblCustomerRecords LEFT JOIN tblCustomerOrders ON " & _
    						"tblCustomerRecords.OrderNumber = tblCustomerOrders.OrderNumber WHERE tblCustomerRecords.OrderNumber=" & OrderNumber
    rs.open()
    %>
    
    </head>
    <body>
    
    <%' while not rs.eof %>
    	<%
    								Dim OrdStat
    								OrdStat = "x"
    								For Each objField In rs.fields
    									Response.Write "<strong>" & objField.name & ":</strong> " & objField.value & " <span style=""color:blue;"">|</span> "
    									If objField.name = "OrderStatus" Then OrdStat = objField.value
    								Next
    								Response.Write "<br /><a href=""del_note.asp?id="&rs("tblCustomerRecords.id")&""">" & rs("tblCustomerRecords.OrderNumber") &"</a>"
    								%>
    								
    
    <div id="wrapper">
    <div id="top"><img src="../../images/build/Delnote_Header.png" /></div>
    <div class="deladdress">
    	DELIVERY ADDRESS<br /><br />
    	<%response.write(rs("ShippingNameTitle")&"&nbsp;"&rs("ShippingFirstName")&"&nbsp;"&rs("ShippingFirstName")&"<br />"& _
    	rs("ShippingAddress1")&"<br />"& _
    	rs("ShippingAddress2")&"<br />"& _
    	rs("ShippingCity")&"<br />"& _
    	rs("ShippingCounty")&"<br />"& _
    	rs("ShippingPostal")&"<br />"& _
    	rs("ShippingCountry"))%>
    </div>
    <div class="date1"><%=FormatDateTime(rs("DateOrdered"),vblongdate)%></div>
    <div class="billaddress">
    	BILLING ADDRESS<br /><br />
    	<%response.write(rs("BillingNameTitle")&"&nbsp;"&rs("BillingFirstName")&"&nbsp;"&rs("BillingFirstName")&"<br />"& _
    	rs("BillingAddress1")&"<br />"& _
    	rs("BillingAddress2")&"<br />"& _
    	rs("BillingCity")&"<br />"& _
    	rs("BillingCounty")&"<br />"& _
    	rs("BillingPostal")&"<br />"& _
    	rs("BillingCountry"))%>
    </div>
    <br />
    <table ID="table" border="1" width="98%" align="center" style="margin-top:10px; margin-bottom:10px;">
    	<tr>
    		<td colspan="5">YOUR ITEMS</td>
    	</tr>
    	<tr>
    		<td colspan="5">&nbsp;</td>
    	</tr>
    	<tr>
    		<td>Code</td>
    		<td>Colour</td>
    		<td>Size</td>
    		<td>Description</td>
    		<td>Price</td>
    	</tr>
    	<% while not rs.eof %>
    	<tr>
    		<td><%=rs("descriptionofgoods")%></td>
    		<td><%=rs("option2")%></td>
    		<td><%=rs("option1")%></td>
    		<td><%=rs("descriptionofgoods")%></td>
    		<td><%=rs("itemPrice")%></td>
    	</tr>
    	<% rs.MoveNext() :: wend %>
    	<tr>
    		<td></td>
    		<td></td>
    		<td></td>
    		<td><style="text-align:right;"><strong>Sub Total<br /><br />Delivery<br /><br />Total</strong></style></td>
    		<td><%=rs("LineTotal")%></td>
    	</tr>
    </table>
    <div id="footer"></div>
    </div>
    <%' rs.MoveNext() :: wend %>
    </body>
    </html>
    Also, Where I have: <%=rs("LineTotal")%> this is in the database but not showing?! I get the error: ADODB.Field error '80020009'

    Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

    /paddycampbell.www.co.uk/www/office/orders/del_note.asp, line 0

  • #2
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    please help

  • #3
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    ok, here is the FOR LOOP to add the items purchased, I need to modify this based on the QTY

    So, INSERT INTO tblCustomerOrders based on the number in the QTY field!

    Code:
    For UCCart1__i=0 To UCCart1.GetItemCount()-1
    	 sql = "INSERT INTO tblCustomerOrders (OrderNumber, [qty], [productCode], [descriptionofgoods], [option1], [option2], [itemPrice], [lineTotal]) VALUES ("
    	 sql = sql & "" & replace(session("OrderNumber"),"'","''") & ", "
    	 sql = sql & "" &	UCCart1.GetColumnValue("Quantity",UCCart1__i) & ", "
    	 sql = sql & "'" & replace(UCCart1.GetColumnValue("ProductID",UCCart1__i),"'","''") & "', "
    	 sql = sql & "'" & replace(UCCart1.GetColumnValue("Name",UCCart1__i),"'","''") & "', "
    	 sql = sql & "'" & replace(UCCart1.GetColumnValue("Size",UCCart1__i),"'","''") & "', "
    	 sql = sql & "'" & replace(UCCart1.GetColumnValue("Colour",UCCart1__i),"'","''") & "', "
    	 sql = sql & "" & replace(UCCart1.GetColumnValue("Price",UCCart1__i),"'","''") & ", "
    	 sql = sql & "" & replace(UCCart1.GetColumnValue("Total",UCCart1__i),"'","''") & ")"
      conn.open
    	  on error resume Next
    Can anyone please help?!

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    The problem with rs("LineTotal") is obvious.

    From YOUR CODE:
    Code:
        <% while not rs.eof %>
                 ...
        <% rs.MoveNext() :: wend %>             ...
        <td><%=rs("LineTotal")%></td>
    You need to MOVE the line in red there to *after* the rs("LineTotal"), of course.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Looks to me like it is picking up the quantity.

    Have you DEBUGGED?????

    Have you done a RESPONSE.WRITE of that SQL??

    Also, you should *NEVER NEVER NEVER* use On Error Resume Next until you get the basic code working. That should *ONLY* be used as a last resort and ONLY if you have code in place that can fix or report the error when it occurs.

    You could be getting lots of errors and your code would just *IGNORE* them. Very very bad when doing development.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Also, you should do the conn.open *ONE TIME* at the top of the ASP page and then NEVER close the connection and use the same connection for ALL operations on the page.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts
    hi, yes it is picking up the QYT but only inserting each record once not twice if teh QTY is 2 or 3 times if WTY is 3?!

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    ??? It should *NOT* insert more than ONE TIME!!!!

    That what the [qty] field in the database is FOR!

    INSERT INTO tblCustomerOrders (OrderNumber, [qty], [productCode], ...

    *THAT* is what tells you, later when you display the data, HOW MANY were ordered.

    It would be a very very silly and (sorry) brain-dead system if it *DID* add one record for each number in the quantity!

    Imagine somebody orders 3,432 of something. Would you *REALLY* want to add 3,432 records to the DB?????
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    You REAL problem is that you don't DISPLAY the quantity in the other page/code!

    You *NEED* to add it in!
    Code:
    	<tr>
    		<td>Code</td>
    		<td>Colour</td>
    		<td>Size</td>
    		<td>Description</td>
    		<td>Quantity</td>
    		<td>Price</td>
    	</tr>
    	<% while not rs.eof %>
    	<tr>
    		<td><%=rs("descriptionofgoods")%></td>
    		<td><%=rs("option2")%></td>
    		<td><%=rs("option1")%></td>
    		<td><%=rs("descriptionofgoods")%></td>
    		<td><%=rs("qty")%></td>
    		<td><%=FormatCurrency(rs("itemPrice"))%></td>
    	</tr>
    	<tr>
    		<td></td>
    		<td></td>
    		<td></td>
    		<td></td>
    		<td style="text-align:right; font-weight: bold;">Sub Total</td>
    		<td><%=FormatCurrency(rs("LineTotal")%></td>
    	</tr>
    	<% rs.MoveNext() :: wend %>
    Your use of
    <br/><br/>Dellivery<br/>Total
    in there makes NO SENSE at all.

    Each line item *should* have a separate subtotal.

    You then *ALSO* need to show the total, but only *AFTER* all the line items.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Exclamation

    Quote Originally Posted by Old Pedant View Post
    You REAL problem is that you don't DISPLAY the quantity in the other page/code!

    You *NEED* to add it in!

    Your use of
    <br/><br/>Dellivery<br/>Total
    in there makes NO SENSE at all.
    I am working on the delivery note! for each Order Number Also, yes I do need to display all records?!

    nobody will buy 2,478 dresses they are really expensive!

  • #11
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    ok

    ok say I want to keep it as it is, QTY = 2

    how would i show that other item as a duplicate?

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    My head hurts.

    *WHAT* "other item"???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •