hello i am making a spoof online book store site for a class and I was
wondering how i could fix a problem i am having. I have two tables, one
the cart and the other a table with book descriptions. what i am trying
to do is display the book info for the cart through a SQL statement.
the only problem is when i do this it just outputs the info for all
books in the database. how would i change my SQL statement to only read
the info for the books listed as ISBNs in the cart.
here is a code snippet watch for text wraps
' count total items in shopping cart
dim intItemCount, dblPrice, curDiscPrice, curPrice, dblSubTotal
dim dblShipping, dblTotalPrice
strSQL="SELECT tblCart.strSess ionID, Sum(tblCart.int Qty) AS SumOfintQty
" & _
"FROM tblCart " & _
"GROUP BY tblCart.strSess ionID " & _
"HAVING tblCart.strSess ionID='" & strSessionID & "'"
objRS.Open strSQL, objConn
If NOT objRS.EOF then
intItemCount = objRS("SumOfint Qty")
else
intItemCount = 0
end if
objRS.Close
'List items in cart
If intItemCount < 1 then
response.write "<center><f ont face='Comic Sans MS'
color='#FF0000' >" & _
"Your Shopping Cart is empty.</font><br><br>"
Else
strSQL="SELECT tblCart.strSess ionID, tblCart.strISBN ,
tblCart.intQty, tblBookDescript ion.ISBN, tblBookDescript ion.strTitle,
tblBookDescript ion.dblPrice " & _
"FROM tblBookDescript ion, tblCart " & _
"WHERE tblCart.strSess ionID='" & strSessionID & "'"
objRS.Open strSQL, objConn
%>
<div align="center">
<center>
<font face='Comic Sans MS' color='#FF0000' >You have <%
=intItemCount %>
book<% If intItemCount > 1 then response.write "s" %> in
your shopping cart.
</font><br><br>
<table cellpadding="4" >
<tr>
<td>Item</td>
<td>Book Title</td>
<td>Qty</td>
<td>Price</td>
<td> </td>
<td> </td>
</tr>
<%
'List each item in cart
dim intCount
do while NOT objRS.EOF
intCount = intCount + 1
%>
<tr>
<td><% =intCount %>.</td>
<td>
<! Book Title, author, stock >
<a href="ProductPa ge.asp?isbn= <% =objRS("ISBN")% > "> <%
=objRS("strTitl e")%> </a>
<br>
<font size="-1">
by <% =funListAuthors (objRS("ISBN")) %></a>
</font>
<br>
</td>
<td><% =objRS("intQty" ) %></td>
<td>
<% curPrice = FormatCurrency( objRS("dblPrice "))
curDiscPrice = FormatCurrency( (objRS("dblPric e")*.8))
dblPrice = (objRS("dblPric e"))
%>
<! Price >
<FONT face=arial,verd ana,helvetica>< B>List Price:
<font color=#990000>< strike><% =dblPrice
%></strike></font><br>
<FONT face=arial,verd ana,helvetica>O ur Price:
<font color=#990000> <% =curDiscPrice %> </font><br>
<FONT face=arial,verd ana,helvetica>Y ou Save:
<font color=#990000>< % =FormatCurrency ((dblPrice -
curDiscPrice)) %>(20%)</b></font><br><br>
<td><a href="?delISBN= <% =objRS("strISBN ")
%>"> Remove</a></td>
<td><a href="?addISBN= <% =objRS("strISBN ")
%>"> Add</a></td>
</tr>
<% objRS.MoveNext
Loop
%> </table>
thanks for the help if you have any questions just ask
Isaac 3 1552
isaac2004 wrote: hello i am making a spoof online book store site for a class and I was wondering how i could fix a problem i am having. I have two tables, one the cart and the other a table with book descriptions. what i am trying to do is display the book info for the cart through a SQL statement. the only problem is when i do this it just outputs the info for all books in the database. how would i change my SQL statement to only read the info for the books listed as ISBNs in the cart.
here is a code snippet watch for text wraps
' count total items in shopping cart dim intItemCount, dblPrice, curDiscPrice, curPrice, dblSubTotal dim dblShipping, dblTotalPrice strSQL="SELECT tblCart.strSess ionID, Sum(tblCart.int Qty) AS SumOfintQty " & _ "FROM tblCart " & _ "GROUP BY tblCart.strSess ionID " & _ "HAVING tblCart.strSess ionID='" & strSessionID & "'" objRS.Open strSQL, objConn
If NOT objRS.EOF then intItemCount = objRS("SumOfint Qty") else intItemCount = 0 end if objRS.Close
'List items in cart If intItemCount < 1 then response.write "<center><f ont face='Comic Sans MS' color='#FF0000' >" & _ "Your Shopping Cart is empty.</font><br><br>" Else
strSQL="SELECT tblCart.strSess ionID, tblCart.strISBN , tblCart.intQty, tblBookDescript ion.ISBN, tblBookDescript ion.strTitle, tblBookDescript ion.dblPrice " & _ "FROM tblBookDescript ion, tblCart " & _ "WHERE tblCart.strSess ionID='" & strSessionID & "'"
Simple debugging - what do you get if you response.write strSQL at this
point in your code?
--
Mike Brind
>Simple debugging - what do you get if you response.write strSQL at this
point in your code?
the SQL is
strSQL:SELECT tblCart.strSess ionID, tblCart.strISBN , tblCart.intQty,
tblBookDescript ion.ISBN, tblBookDescript ion.strTitle,
tblBookDescript ion.dblPrice FROM tblBookDescript ion, tblCart WHERE
tblCart.strSess ionID='vtypj355 4213ri55s5za3lr n'
this means it is relying on the the Session ID and grabbing all books
out of the tblBookDescript ion, how would I just grab the books in the
cart tbl. thanx
isaac2004 wrote: Simple debugging - what do you get if you response.write strSQL at this point in your code?
the SQL is strSQL:SELECT tblCart.strSess ionID, tblCart.strISBN , tblCart.intQty, tblBookDescript ion.ISBN, tblBookDescript ion.strTitle, tblBookDescript ion.dblPrice FROM tblBookDescript ion, tblCart WHERE tblCart.strSess ionID='vtypj355 4213ri55s5za3lr n'
this means it is relying on the the Session ID and grabbing all books out of the tblBookDescript ion, how would I just grab the books in the cart tbl. thanx
I think you have the cartesian product of two tables in the result of
your query. This is because you haven't joined them properly in your
SQL. The SQL should be:
SELECT tblCart.intQty, tblBookDescript ion.ISBN,
tblBookDescript ion.strTitle, tblBookDescript ion.dblPrice FROM tblCart
INNER JOIN tblBookDescript ion ON tblCart.strISBN =
tblBookDescript ion.ISBN WHERE tblCart.strSess ionID='" & strSessionID &
"'"
I would suggest that in future, when you are trying to get results from
more than one table, you should use the Access Query Builder to test
your query. Once you have found it works, switch to SQL view and use
the SQL Access produces for you.
You also need to have a look at the Access Online help with regard to
joining tables. If you don't explicitly join the tables (and you do
his by dragging the primary key from one table to the foreign key in
the other so you get a black line joining them, or by defining table
relationships in the relationships pane), you will get all the results
from one table x the matching records in the other. So, if your cart
has two books in it, and your books table has 10 books in, you will get
a recordset of 20 books (that is, all books twice).
Also, in your original code, you unnecessarily selected the ISBN number
in tblCart, when it is also in tblBookDescript ion, and the SessionID,
which you already have in strSession.
--
Mike Brind This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: laurie |
last post by:
Hi all,
I'm trying to help out a friend who has inherited a client with a PHP
shopping cart application. Neither of us know PHP, but I've been
muddling my way through, trying to get these old scripts working on a
new server with the most recent version of PHP. I've pretty much
taken care of all the various errors that were popping up. Most only
pointed out out non-fatal undefined or assumed variables. I've been
able to cure most of...
|
by: mbeddedsoft |
last post by:
I'm trying to use access as the database for a website. I don't expect
too much traffic initially and I didn't want to bother with a more
robust/complex db. Anyway, I have this 2 tables:
Cart{
cartId == userSessionId
subTotal == totalCost of all items in cart
item == (1 or more Items)
}
|
by: Paul Hobbs |
last post by:
Hi All,
I am developing a site that makes use of a standard shopping cart. Anyone
can add items to the cart, but only registered users can actually check out.
When a user tries to check out, if they are not logged in they will be
prompted to either login or register before they can proceed to the
checkout.
There is NO requirement to allow users to add items to a shopping cart, and
return at some time in the future and still have...
|
by: VB Programmer |
last post by:
I am making a data driven shopping cart.
I'm using a datalist for the list of products. The item template consists
of:
- Product Id
- Product Picture
- Product Description
- Price
- Qty
- Add to Cart image button
|
by: isaac2004 |
last post by:
hi i have a basic asp page that acts as an online bookstore. on my cart
page i am having trouble generating 3 numbers; a subtotal, a shipping
total, and a final price. here is my code
i would like it to work properly so that a record count counts through
all the books and genertates these numbers. watch out for line breaks
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include file="DatabaseConnect.asp"-->
| |
by: isaac2004 |
last post by:
hi i am creating a basic asp site that uses cookies to manage a cart
for an online store. whenever i open this page without adding anything
to the cart. i get an error message.
here is my code
<%@ Language=VBScript %>
<% Option Explicit %>
<!--#include file="DatabaseConnect.asp"-->
<!--#include virtual="06winter/levini/database/adovbs.inc"-->
|
by: isaac2004 |
last post by:
hi i am trying to send a html message that reiterates a invoice from a
online store site im making, i have the invoice written to the browser
but i would also like to send one to the customer via email
here is the code for the browser part
dim strSessionID, strISBN, strTitle
'open database for cart
strSQL = "SELECT tblCart.strSessionID, tblCart.strISBN, tblCart.intQty,
tblBookDescription.strTitle, tblBookDescription.dblPrice " & _
|
by: vincemoon |
last post by:
Sites such as download.com, dealtime.com, shopping.com, and tucows.com,
feature impressive sortable lists of products.
What software that imports CSV can be used to generate database-driven
sortable product listings such as shown on such sites?
I am already able to get CSV into sortable (by javascript) HTML tables
that do not use databases, but there are problems with this such as the
slow sort time when there are many items, the...
|
by: pereges |
last post by:
Hello, I'm trying to build a database driven website for a library
management system. The database is stored on a remote server which all
of my team mates can access. I've installed MySQL, PHP and Apache on
my machine. I'm a beginner and I really don't understand how to
proceed. My biggest problem is how to connect to the database on
remote mysql server ? Does php allow this kind of thing ? I'm
interested in a web interface on my machine...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |