...

View Full Version : Accessing previous orders via query string



SAND
03-21-2007, 09:46 PM
Hi everyone,

Upon clicking View Orders I see this:

http://xs413.xs.to/xs413/07123/vieworders1.PNG

But I want to be able to see this:

http://xs413.xs.to/xs413/07123/vieworders2.PNG

This is my select statement:
SELECT [OrderID], [CustomerID], [OrderDate], [TotalPrice] FROM [Orders] WHERE ([CustomerID] = ?)

I would appreciate any guidance on this.

Thanks for reading.

nikkiH
03-21-2007, 10:39 PM
Well, both pics show your user name.
So, where's that coming from?
Plug that into the query.

SAND
03-21-2007, 10:41 PM
That`s the thing, I don`t want the username in the query, because I want to use the query for a number of pages.

The username is just coming from the ASP option of LoginName.

nikkiH
03-22-2007, 03:09 PM
Are you saying that it is not available on the other pages where you need it?
If that's the case, you can save it in a session variable.

SAND
03-22-2007, 07:26 PM
How would I go about that? I think that sounds about correct; yes.

nikkiH
03-22-2007, 08:51 PM
Pretty basic.

http://samples.gotdotnet.com/quickstart/aspplus/doc/stateoverview.aspx#sessionstate

SAND
03-22-2007, 09:16 PM
Ok, I have read through that, but don`t have a clue.

Would it do my task of querying the information?

Here is the select statement I am using:


SELECT [OrderID], [CustomerID], [OrderDate], [TotalPrice] FROM [Orders] WHERE ([CustomerID] = ?)

What would I be declaring in the session variable as I only want a match between customer id's, but not by declaring a name.

nikkiH
03-22-2007, 09:21 PM
From what I gather from your picture, the customer id is khana.
You want to store that id for use later, is that correct?

SAND
03-22-2007, 09:23 PM
I want each user to be able to view their previous orders. So I want the user that is logged in to access their order and only their order.

nikkiH
03-22-2007, 10:34 PM
It appears that the user name and the user id are identical from this example. In which case, you don't need the id, because you already have it.
Is this not normally the case?
If not, I assume there is a one-to-one relationship between the logged in user and the user's customer ID.

SELECT [OrderID], [CustomerID], [OrderDate], [TotalPrice] FROM [Orders] WHERE ([CustomerID] = ?)

Somewhere, a user has a customer ID. You can join on that table and just grab it like that.

A pure query, using khana and assuming a table called Users that has a UserName column and a CustomerID column...

SELECT [OrderID], [CustomerID], [OrderDate], [TotalPrice] FROM [Orders] JOIN Users on Orders.CustomerID=Users.CustomerID
WHERE ([UserName='khana')

SAND
03-22-2007, 10:46 PM
I get exactly what you`re saying, but if I have 50 users, that would be really time-consuming.

There must be a simpler method, that`s why I`m trying a query string where it only finds the matches with the logged in user and the Customer ID.

nikkiH
03-23-2007, 03:47 PM
That's exactly what that does.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum