View Full Version : Accessing previous orders via query string

03-21-2007, 10:46 PM
Hi everyone,

Upon clicking View Orders I see this:


But I want to be able to see this:


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

I would appreciate any guidance on this.

Thanks for reading.

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

03-21-2007, 11: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.

03-22-2007, 04: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.

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

03-22-2007, 09:51 PM
Pretty basic.


03-22-2007, 10: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.

03-22-2007, 10: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?

03-22-2007, 10: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.

03-22-2007, 11: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')

03-22-2007, 11: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.

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