Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting items and displaying unique info.

Status
Not open for further replies.

Shilohcity

Technical User
Jul 12, 2000
136
GB
Hi there

I am new to asp and have the following problem:

I am trying to sort out a page which displays the contents of a table from a database and gives the option of selecting certain items (for shopping purposes). This is fine but the page which processes this information has me stumped. I am having trouble getting the script to recognise whether an item is selected or not as the information is being forwarded as a string. When I break down the selection info into a separated array it gets a little better but is still taking all of the information in the table instead of the selected records. I guess basically I need to figure out how to uniquely identify the records, keep them as separate records when displayed and pass this information to a new table

Dim objRS, stritemselect, arritemselect, sepitemselect, itemselect
'gather itemselect status and separate up
stritemselect = Request.Form("itemselect")
arritemselect = Split (stritemselect, ",", -1, 1)
For Each sepitemselect in arritemselect
Response.Write sepitemselect
Set objRS=Server.CreateObject("ADODB.Recordset")
objRS.Open "iteminfo",objConn,,adLockOptimistic, adCmdTable
Do While Not objRS.EOF
Response.Write objRS("itemprice")
Response.Write objRS("itemtype")
objRS.Update
objRS.MoveFirst
Loop
Response.Write (&quot;<BR>&quot;)
Next

'if itemselect is positive then write to itemorder table
For itemselect = LBound(arritemselect) to UBound(arritemselect)
Set objRS=Server.CreateObject(&quot;ADODB.Recordset&quot;)
objRS.Open &quot;itemorder&quot;,objConn,,adLockOptimistic, adCmdTable
objRS.AddNew
objRS(&quot;itemselect&quot;) = Request.Form(&quot;itemselect&quot;)
objRS(&quot;itemid&quot;) = Request.Form(&quot;itemid&quot;)
objRS(&quot;itemtype&quot;) = Request.Form(&quot;itemtype&quot;)
objRS(&quot;itemcolour&quot;) = Request.Form(&quot;itemcolour&quot;)
objRS(&quot;itemsize&quot;) = Request.Form(&quot;itemsize&quot;)
objRS(&quot;itemprice&quot;) = Request.Form(&quot;itemprice&quot;)
objRS.Update
objRS.MoveFirst
 
It all depends on how you want to uniquely indentify each item. I would use a autonumber in the database to identify the item, that way when you list out the items that can be selected you can allocate the autonumber as their value and pass this autonumber to the next page as your string anc collect it using:

stritemselect = Request.Form(&quot;itemselect&quot;)

then, instead of using an array to store the selected item identifier I would simply create a recordset and get from the database the items that have been selected using an SQL statement like:

&quot;select * from YOURTABLENAME WHERE AutonumberField IN (&quot;&amp;stritemselect&amp;&quot;)

This will create a recordset that contains all selected Items and you can then scroll through, display them etc.. with ease at the same time adding the item to the order table in your database.
Hope this helps. You can also use the above method to delete a selected set of items from a database.
sjf
 
Hi there

Thanks for your help above. I was getting a little muddled over a few things...anyway I have followed your advice and used a SQL statement I already have the form on the previous page set up to use the itemid code which is an Autonumber field. I am however having a few problems with getting the SQL statement to work. It works fine when I set it to an absolute value (or use the test string) but when I insert the itemselect string it returns an error message related to the fact there are commas inserted in the string. I have tried separating the string using a Split command into a new array and inserting this array into the statement but still recieve an error message related to having a missing operator. I get the feeling I am very close to having this working and would appreciate any help you can offer.

Here is my code so far:
Dim itemselect, test
itemselect = Request.Form(&quot;itemselect&quot;)
test = 5

Dim arritemselect, stritemselect, strSQL
arritemselect = Split(itemselect, &quot;,&quot;, -1, 1)
For Each stritemselect in arritemselect
Response.Write (stritemselect)
Response.Write (&quot;<BR>&quot;)
Next
strSQL = &quot;Select * FROM iteminfo WHERE itemid = &quot;&amp;stritemselect&amp;&quot; &quot;

Dim objRS
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)

objRS.Open strSQL, objConn


Response.Write &quot;is the code going to work?&quot;
Do While Not objRS.EOF
Response.Write objRS(&quot;itemid&quot;)&amp;&quot;,&quot;&amp;objRS(&quot;itemcolour&quot;)
Response.Write(&quot;<BR>&quot;)
objRS.MoveNext
Loop

'Clean up ADO objects
objRS.Close
Set objRS = Nothing

objConn.Close
Set objConn = Nothing

Thanks
Justin


 
I think the problem lies in the use of the array. The SQL statement I suggested:
&quot;select * from YOURTABLENAME WHERE AutonumberField IN (&quot;&amp;itemselect&amp;&quot;)&quot;

Does not require an array to be created, the &quot;itemselect&quot; variable has all the values required stored in comma deliminated form and the IN statement will scroll through those and select them.

Try commenting the array stuff and using the set notation SQL statement above and see how it goes.
sjf.
email me at simonf@ozemail.com.au if you have further problems.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top