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
    New Coder
    Join Date
    Mar 2006
    Location
    United Kingdom of Great Britain and Northern Ireland
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing previous orders via query string

    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.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Well, both pics show your user name.
    So, where's that coming from?
    Plug that into the query.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Mar 2006
    Location
    United Kingdom of Great Britain and Northern Ireland
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Mar 2006
    Location
    United Kingdom of Great Britain and Northern Ireland
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How would I go about that? I think that sounds about correct; yes.

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #7
    New Coder
    Join Date
    Mar 2006
    Location
    United Kingdom of Great Britain and Northern Ireland
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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.

  • #8
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    From what I gather from your picture, the customer id is khana.
    You want to store that id for use later, is that correct?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #9
    New Coder
    Join Date
    Mar 2006
    Location
    United Kingdom of Great Britain and Northern Ireland
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #10
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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')

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #11
    New Coder
    Join Date
    Mar 2006
    Location
    United Kingdom of Great Britain and Northern Ireland
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    That's exactly what that does.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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