Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 12th, 2003, 11:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old June 13th, 2003, 01:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Sydney, NSW, Australia.
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine if numeric Scootterp Access VBA 4 March 2nd, 2006 08:44 AM
Determine Credentials bmumph C# 2 November 1st, 2005 12:18 PM
syntax error on <option selected="selected"> hamid HTML Code Clinic 1 October 13th, 2004 09:20 AM
Determine OS adman Beginning VB 6 2 January 5th, 2004 02:26 AM
Need Help: Can't determine cause of error xgbnow Visual C++ 3 September 22nd, 2003 05:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.