|
|
 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

June 13th, 2003, 12:15 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 243
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Determine if something has already been selected
Can somebody suggest a more effiecient way to do this. I have a list of items and you can add these items to what is basically a simple shopping cart. What I am wanting to do is when you return to the list I want to be able to determine what has been selected.
Right now this runs kind of slow when you have about 20 items per page. What I am doing is I have two select statements one for the Items and one for the cart. From there I am doing the following
While Not objItem.EOF
Response.Write objItem("ItemName")
While Not objList.EOF
If objItem("ItemID") = objList("ItemID_List") Then
Response.Write "Selected"
End If
objList.MoveNext
Wend
objItem.MoveNext
Wend
It seems there would be a better way I have tried JOINS on the select statement but cannot get those to work correctly, if that would be faster I will go back to trying to get those to work.
All help is greatly appreciated.
Thanks
__________________
Peace
Mike
http://www.eclecticpixel.com
|

June 13th, 2003, 02:02 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Sydney, NSW, Australia.
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm not really sure what/how you're showing your selected items. That said, instead of an inner loop for each item in the outer loop, you can do this more efficiently, with only a single loop through each collection by:
a) ordering each collection the same way (eg by ItemID ascending).
b) As you go through each item in the outer loop, you check to see if the current item in the inner loop the same value (in which case write "selected"), or a lower value (shouldn't occur), and in which case advance the inner loop by one step.
So, suppose you have items 1,2,3,4,5,6,7,8 and the user has items 2 and 4 in their basket. Outer array (1,2,3,4,5), Inner Array (2,4)
For the first iteration, the value of the outer array is 1, and the inner array is 2, so you just write out "1"
For the second iteration, the value of the outer array is 2, and the value of the inner array is 2, so you write out "2 selected", -and- advance the inner array to the next element.
For the third iteration, the value of the outer array is 3, and the value of the inner array is 4, so you just write "3"
For the fourth iteration, the value of the outer array is 4, and the value of the inner array is 4, so you write "4 selected", -and- advance the counter for the inner array.
For -all- subsequent iterations (5,6,7,8), you know you have already gone past the last value in the inner array, so you just write them out without having to do any checking.
Cheers
Ken
www.adOpenStatic.com
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |