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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check box comparison 1

Status
Not open for further replies.

nonprogrammer

Technical User
Dec 28, 2005
143
US
Hello,

I am trying to build an asp page that has different items with check boxes. Up to this point everything seems to be working. Where I am having problems is with the logic.
I want to be able to compare item a to item b both items have that same data fields hight, with, weight. Can anybody point me in the right direcction?
 
Tarwn, using your method above to take the list of partnum's to pull down each record can you easily sort the results or should you parse out and sort the partnum list prior to performing the query? Or be better off storing the results in an array and sorting the array before output?

Just curious, I have not had to pull down data like this before.


It's hard to think outside the box when I'm trapped in a cubicle.
 
Tarwn,
I really appreciate all your help!!!! Thank you so very much.




theniteowl,

The number of check boxes depends on the number of parts that my search gives me, it could be 1 or it could be 5.

I really, really appreciate all the help.


 
Tarwn,

For My check box I started with something like this

Code:
<form name="form" method="post" action="comparisonprocess.asp">

<input name="checkbox" type="checkbox" <%If myrs.Fields("checkbox").Value =false then  Response.Write "unchecked" else Response.Write "checked"  End If  %> >

Code:
and the comparisonprocess would look something like this

[code]
'Dimension variables
Dim adoCon 			'Holds the Database Connection Object
Dim rschkbx		'Holds the recordset for the record to be updated
Dim strSQL			'Holds the SQL query for the database
Dim lngRecordNo			'Holds the record number to be updated

'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("ID"))

'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("aqform.mdb")

'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=guestbook"

'Create an ADO recordset object
Set rschkbx = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT aq.* FROM aq WHERE ID=" & lngRecordNo

'Set the cursor type we are using so we can navigate through the recordset
rschkbx.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rschkbx.LockType = 3

'Open the tblComments table using the SQL query held in the strSQL varaiable
rschkbx.Open strSQL, adoCon

'Update the record in the recordset

rschkbx.Fields("createjobrecord") = (Request.Form("createjobrecord")="on")




'Write the updated recordset to the database
rschkbx.Update

'Reset server objects
rschkbx.Close
Set rschkbx = Nothing
Set adoCon = Nothing

'Return to the update select page incase another record needs deleting
Response.Redirect "comarison"
%>

 
my mistake the
Code:
rschkbx.Fields("createjobrecord") = (Request.Form("createjobrecord")="on")

sould be

Code:
rschkbx.Fields("checkbox") = (Request.Form("checkbox")="on")
 
Hmm, on the sorting thing. I'm not sure. I guess it would depend on how you planned on sorting. If you wanted to sort based on a value that had a fielf in the DB then I would definately do that with the SQL statement's ORDER BY clause. There isn't any real built-in sorting for ASP and the VBScript implementations for sorting I have seen generally don't apporach the same level of speed or efficiency as a dedicated database server.

Technically it doesn't matter what order your checkbox list is in, it's going to scan the records in whatever order it is holding them internally and filter out the ones not in the list. So the list doesn't determine any kind of ordering. Probably your best bet is to pass on a value in the form from the previous page to specify what kind of ordering you were doing so you could represent those selections in the same order they appeared on the selection page.

-T

barcode_1.gif
 
Yep, thats sort of what I was thinking with the titles down the first column and products in subsequent columns. It feels a little more natural to compare across like that for several products that it would to compare down a list. That may just be too much internet shopping in my past though :)

barcode_1.gif
 
The last example I gave was a part-per-column layout example. Basically when you get your data back from the database (recordset) it's easiest to output it in rows as you loop through the recordset. Once we switch it to an array with GetRows then you can loop through it by columns instead, as my example does above.

barcode_1.gif
 
Assuming you have some sort of unique id for the records (or that the product number is unique for a product) you would generae some sort of product listing page with the checkboxes next to each entry. The checkboxes should all have the same name and have a value of the product number or unique id. Since checkboxes only pass their value through the form if they are checked, what you will get on the comparison page will be a comma-space delimited list of the selected products.

Several posts up I showed how to add that to a SQL statement. Here is a repeat of that example:
Code:
[COLOR=red]If your using numeric id's[/color]
strSQL = "SELECT productName, width, height, etc FROM Products WHERE productID IN (" & Request.Form("MyCheckboxField") & ")"

[COLOR=red]If your using a text/varchar field[/color]
Dim tStr
tStr = "'" & Replace(Request.Form("MyCheckboxField"),", ","','"  & "'"
strSQL = "SELECT PartNumber, Height, Hub FROM Parts WHERE PartNumber IN (" & tStr & ")"

You would probably want to do a Replace on single quotes first to prevent SQL injection attacks, but other than that it is fairly straight forward. In the first case we are fine just dumping the list of numbers into the SQL string, in the second case we are replacing the comma-space between the values with quote-comma-quote and the add a quote to the front and back of the string, resulting in each entry being surrounded by quotes.

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top