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

Select records to show on action page 2

Status
Not open for further replies.

toyt78

Technical User
Apr 5, 2005
125
0
0
US
I have a page that list all my records in an Access 2000 database.

I want to be able to check boxes next to specific records and then show those records only on the action page.

I seem to be having problem fetching the checked checkboxes where it always shows all the records on the action page instead of just the records I selected (checked).

Please advise.

Code:
<cfquery name="queOne" datasource="dsn">
SELECT *
FROM theTable
</cfquery>
<cfoutput query="queOne">

<form method = "post" action = "theActionPage.cfm">
<input type="Checkbox" value="#ID#" name="theCheck"> #name#

</cfoutput>
<br>
<input type="Submit" value="Submit">
</form>

theActionPage.cfm page
Code:
<cfparam name="form.theCheck" default="">
<cfquery name="que" datasource="dsn">
SELECT *
FROM theTable
</cfquery>

<cfoutput query="dsn">
<cfif listLen(form.theCheck) gt "">
  #ID# #name#<br>
</cfif>
</cfoutput>
 
The checkbox will return a comma delimted list.

I would use the IN clause in SQL to limit my results to those results

Code:
<cfparam name="form.theCheck" default="">
<cfquery name="que" datasource="dsn">
SELECT *
FROM theTable 
WHERE ID IN (#FORM.theCheck#)
</cfquery>

<cfoutput query="que">
  #que.ID# #que.name#<br>
</cfoutput>

Also, the query name in the cfoutput was set to the datasource not the name.

Kris Brixon
www.brixon.org
 
actually, the way the first page is coded, there are N forms, all named the same, and each one contains only one checkbox

what the action page receives is probably only the last form, with exactly one checkbox, and it'll be either checked or not

so why does it show all the records?

because whether it is checked or not, you CFPARAM the checkbox to an empty string!

this means it exists, which means that listLen(form.theCheck) will always be 1

why 1? because ListLen gives you the number of elements in the list

now, you tell me, is 1 greater than an empty string?

looks like it is, which is why you get all the records printed


:)

r937.com | rudy.ca
 
good eye Rudy, there are multiple problems. I missed that.

Change:
Code:
<cfoutput query="queOne">
<form method = "post" action = "theActionPage.cfm">

To:
Code:
<form method = "post" action = "theActionPage.cfm">
<cfoutput query="queOne">

Your first page has many <form> tags and one </form> tag.

Kris Brixon
www.brixon.org
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top