Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How should i write the code for my basket window?

Status
Not open for further replies.

Beracosta

Programmer
Oct 25, 2000
47
SE
Hi! I sure hope that i'll get as good help that i have had on my other questions. I have this problem, i want the shopping basket to be in a frame so the customer always will see what the basket contains... but i can solve this... pls help me... this is the code for ShowBasket.asp:

<html>
<head><title>Global Kockknivar</title></head>
<body bgcolor=&quot;ffffff&quot; text=&quot;#000000&quot; link=&quot;#008000&quot; alink=&quot;#808000&quot; vlink=&quot;#800000&quot;>

<%
Dim oRs
Dim strSQL

Set oRs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
With oRs
.ActiveConnection = &quot;DSN=SYCENT;&quot;
.CursorLocation = 3
.CursorType = 3
.LockType = 4
strSQL = &quot;SELECT Name, Quantity, Price FROM BasketContent &quot; & _
&quot;INNER JOIN Merchants ON BasketContent.MerchantID = Merchant.Id &quot; & _
&quot;WHERE BasketContent.BasketId = &quot; & Request(&quot;BasketID&quot;)
.Open strSQL
Set .ActiveConnection = Nothing
While Not oRs.EOF
Response.Write &quot;Name: &quot; & oRs(&quot;Name&quot;).Value & &quot; Quantity: &quot; & oRs(&quot;Quantity&quot;).Value & &quot; Tot Price: &quot; & oRs(&quot;Quantity&quot;).Value * oRs(&quot;Price&quot;).Value & &quot;<br>&quot;
oRs.MoveNext
Wend
.Close
End With
Set oRs = Nothing
%>


</body>
</html>

can someone pls help me?
 
Firstly, don't set the ActiveConnection to nothing until after you have processed the loop, that might be causing a problem.

Secondly, calculate the total price into a variable, and then use this variable in the response.write. Although this means an extra line of code, it will probably prove more efficient in the long run. It does in VB.

Thirdly, there is no need to set the lock type as you are using a static cursor so the default of ReadOnly is fine as you can't modify the data using this cursor type. James Culshaw
jculshaw@active-data-solutions.co.uk
 
But.... when i use this code... the window that shows ShowBasket.asp just gets a error msg when i entre the site... it's something with
BasketContent.BasketId = BasketID ......

how should i write the code? thanx in advance
 
At the moment i type the basketid manually but in the goal is to have a BasketID that is gererated and saved in a cookie so the costumer always has it's own unic basket when he/she comes to my site... i haven't solved this either. =)

 
What database are you talking to? I may be able to help with the generation of an ID.
Did you not post this question? I think I answered that one somewhere else on this forum!

Try this code:

Code:
<%
    Dim oRs
    Dim strSQL
    Dim intValue

    Set oRs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
    With oRs 
        .ActiveConnection = &quot;DSN=SYCENT&quot;
        .CursorLocation = 3
        .CursorType = 3
        strSQL = &quot;SELECT Name, Quantity, Price FROM BasketContent INNER JOIN Merchants ON BasketContent.MerchantID = Merchant.Id WHERE BasketContent.BasketId = {put a known basket id here}&quot; 
        .Source = strSQL
        .Open 
        While Not oRs.EOF
            Response.Write &quot;Name: &quot; 
            Response.Write oRs(&quot;Name&quot;)
            Response.Write &quot; Quantity: &quot;
            Response.Write oRs(&quot;Quantity&quot;)
            Response.Write &quot; Tot Price: &quot;
            intValue = oRs(&quot;Quantity&quot;) * oRs(&quot;Price&quot;) 
            Response.Write intValue
            Response.Write &quot;<br>&quot;
            oRs.MoveNext
        Wend
        .Close
    End With
    Set oRs = Nothing
%>

By putting a known basket ID into the SQL then you can test the SQL with known values.
Another option is to get the ASP to
Code:
Response.Write
the SQL onto the page, and then run this SQL directly against your DB and see the results or error messages that appear. If you then have problems then post them back here and I'll try to help.

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top