If I can use several CFIF to do  the query based on the different choice made by the user?

xiaobing
xiaobing used Ask the Experts™
on
I have a project that I want the user to choose one of the 4 possible period time to view the sales situation during the specific period, the type for the time is "radio" , for example: this week, last week,last month, from today forward , also, I will give the user another choice, they can specific a beginning and ending time also. How can I do the query to match different choice? I think the query that I will do will be different with the choice "this week" and "this month". I wonder if I can use several if else to do that? that is, if they choose this week, I will do a different query, if they choose "this month", the query condition also will be different? but how about the query if they user specify the time by themself rather than to choose one.
Thank!
Bing!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you can do an if else block like this...

SELECT blah FROM blah
WHERE 1=1
<CFIF period eq 1>
AND [CODE FOR THIS WEEK ONLY]
<CFELSEIF period eq 2>
AND [CODE FOR LAST MONTH ONLY]
<CFELSEIF period eq 3>
AND [CODE FOR TODAY FORWARD]
<CFELSEIF period eq 4>
AND [CODE FOR SPECIFIC PERIOD use #datefrom# and #dateto#]
</CFIF>

you ask for "datefrom" and "dateto" in your form if the user selects option #4

Author

Commented:
Good suggestion, thanks a lot! But i still have a question about it, if I will do different query with different if condition? Based on the code that you gave me, it looks like I only need to do one select query, but i think maybe will do 4 different select...from...where query, becuase the where condition is different. I hope you can help me again.
Thanks!

Commented:
<cfparam name="myvalue" default="">

<cfswitch expression="#myvalue#">
    <cfcase value="1">
       SELECT blah FROM blah
WHERE 1=1
<CFIF period eq 1>
AND [CODE FOR THIS WEEK ONLY]
<CFELSEIF period eq 2>
AND [CODE FOR LAST MONTH ONLY]
<CFELSEIF period eq 3>
AND [CODE FOR TODAY FORWARD]
<CFELSEIF period eq 4>
AND [CODE FOR SPECIFIC PERIOD use #datefrom# and #dateto#]
</CFIF>

   </cfcase>
   <cfcase value="2">
      different query...
     
   </cfcase>

    <cfdefaultcase>
       put the default thing to do
    </cfdefaultcase>

</cfswitch>

don't forget to put cfquery part accordingly.


Author

Commented:
Thanks so much. I am so sorry to bother you again because I am trying to add another function to my page. That means, above the 4 time period choices, I want to add a major drop down list, that means, after the user specify a major and then choose one time period, he can view the registration information about only one major and only with the period that he specified.
The new problem is how can I join these two conditions together: the major and the time?
Have a nice weekend!
Xiaobing

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial