How to filter query results based on selection from dropdown list
NickName:Madeva Reddy Ask DateTime:2015-06-11T12:48:35

How to filter query results based on selection from dropdown list

I have two tables: foodrequest and employeedetails. I am able to search the records from those tables, by date, based on a "FromDate" and "ToDate" values like this:

<cfset var qryFoodRequest = queryNew("")>       
<cfset var localData = structNew()>

<cfif (structKeyExists(Form,"Fromdatepicker") AND isDate(Form.Fromdatepicker) ) 
      AND (structKeyExists(Form,"Todatepicker") AND isDate(Form.Todatepicker) )>
    <cfset localData.frmDate = listGetAt(Form.Fromdatepicker,3,'/') & '-' & listGetAt(Form.Fromdatepicker,2,'/') & '-' & listGetAt(Form.Fromdatepicker,1,'/')>
    <cfset localData.toDate = listGetAt(Form.Todatepicker,3,'/') & '-' & listGetAt(Form.Todatepicker,2,'/') & '-' & listGetAt(Form.Todatepicker,1,'/')>
</cfif>


<cfquery name="qryFoodRequest" datasource="ebms"  cachedWithin = "#createTimeSpan(0,0,0,5)#">
    SELECT  e.FullName FullName
            , e.EmployeeCode EmployeeCode
            , e.DesignationName DesignationName
            , e.DateOfJoin DateOfJoin
            , e.DepartmentName DepartmentName
            , e.ManagerName ManagerName
            , e.ParentOffice ParentOffice
            , f.Requesttype Requesttype
            , f.Foodtype Foodtype
            , f.ReqDate ReqDate
            , f.remarks remarks
    FROM    foodrequest f INNER JOIN employeedetails e 
                 ON  f.EmployeeId = e.empId 

    <cfif structKeyExists(localData,"frmDate") AND structKeyExists(localData,"toDate")>
        AND f.ReqDate between ('#localData.frmDate#') and ('#localData.toDate#')
    </cfif>     
    order by e.empId;
</cfquery>          

<cfreturn qryFoodRequest>

But I am not able to search by employee. I.e. If I select any employee from a dropdown list, it will return their records only.

Can anybody help me on this?

Copyright Notice:Content Author:「Madeva Reddy」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30771782/how-to-filter-query-results-based-on-selection-from-dropdown-list

More about “How to filter query results based on selection from dropdown list” related questions

Django - Filter and display a model based on dropdown selection

I would like to display a table from a model that is filtered based on a dropdown box selection. I created a drop down using form. The values in the dropdown are distinct values of sensor_loc_blg. ...

Show Detail

Limit Number of Results for Autocomplete Based on Dropdown Selection

I'm trying to figure out a couple things here and seem to be pretty close but hit a road block. My issue is, after I select a dropdown option (used to filter a large number of results), the results...

Show Detail

Automatic updating of query shown in a form based on dropdown selection

I thought this was going to be the easiest question ever to solve, but after spending a morning searching for answers, I still can't get it to work. I have a list box showing data for certain coun...

Show Detail

How to filter a dropdown list based from the text on a already pre selected list

I am trying to filter the dropdown list based on the text from the first pre-selected list. The first list is contains 'United States' as pre selection and the list to be filtered is the second dro...

Show Detail

Joomla database query based on dropdown selection

I am very new to programing but after a lot of research i can rufly manage to create a dropdown selection from database and show a column result from that table based on the dropdown selection us...

Show Detail

Number of dropdowns based on selection of first dropdown

Programming in Bootstrap and PHP I am trying to create a dynamic form which has the following. User uses a dropdown to select number from 1 to 10. The page then displays x number of dropdowns. Each

Show Detail

How to populate dropdown list based on selection of another dropdown (Wordpress Form Maker)

I'm trying to populate a second dropdown list based on selection from a first dropdown list using WordPress plugin Form Maker by WebDorado. I have two tables on MySQL db "Company" and "Branches" wh...

Show Detail

Filter a dropdown based on the content of another dropdown in PowerApps

I need to filter a dropdown list from the results of another dropdown list above it. I'm filtering personnel based on their respective agency, so when the user selects their Agency from the first

Show Detail

laravel - dynamic dropdown list based on previous selection

I have a dropdown list that is being populated from my database, but I am trying to make a 2nd dropdown list that is based on the first lists selection. The 2nd dropdown lists contents have an FK

Show Detail

How to populate dropdown list from mysql db and based on selection populate another dropdown list in php form?

I have situation where i have column in mysql table from which i populate dropdown list for criteria for query for second dropdown list from another table. How coud i do that using php and selectio...

Show Detail