Skip to main content
Inspiring
April 20, 2010
Question

Building search filters by passing parameters

  • April 20, 2010
  • 2 replies
  • 524 views

Hiya,

I'm trying to build a search filter by cliking on headers of my table. So the order by clause of the query is built on the fly. I can't get the string to have more that 1 item. Can anyone help?

Thanks

Links:

  <thead>
  <td ><a href="?area=joblog/index&sort=jobname" >Title</a></td>
    <td ><a href="?area=joblog/index&sort=jobdeadline" >Deadline</a></td>
    <td ><a href="?area=joblog/index&sort=jobpriority" >Priority</a></td>
    <td><a href="?area=joblog/index&sort=jobfor" >Customer</a></td>
    </thead>

code:

<cfparam name="filter" default="">
<cfif isdefined("sort")>
  <cfif listlen("filter") eq 1 >
    <cfset filter =  filter & ", " &  sort>
    <cfelse>
    <cfset filter =  sort>
  </cfif>
  <cfelse>
  <cfset filter = "jobname">
</cfif>

<cfquery name="get" datasource="joblog">
SELECT     *
FROM job
                     
                      INNER JOIN
                      priority ON job.jobpriority = priority.priorityid
                               
                      WHERE job.jobcomplete = 'false'
                     
                      ORDER BY 
              
                      #filter#
                     
        
</cfquery>

    This topic has been closed for replies.

    2 replies

    Inspiring
    April 20, 2010

    You won't be able to do it with anchor tags.  You'll need form fields that enable the user to enter numbers.

    Participating Frequently
    April 20, 2010

    How about like this?

    <cfparam name="URL.sort" default="jobname">

    <cfquery name="get" datasource="joblog">
    SELECT     *
    FROM job
    INNER JOIN priority ON job.jobpriority = priority.priorityid
    WHERE job.jobcomplete = 'false'
    ORDER BY #URL.sort#
    </cfquery>

    Ken Ford