pntyhs Posted October 9, 2012 Share Posted October 9, 2012 (edited) I am creating a search page with php and codeigniter. I created the query which is; "SELECT * FROM my_account WHERE inex='$inex' AND type='$type' AND date BETWEEN '$date1' AND '$date2' " $date1 and $date2 values comes from form input and I have no problem here. On the other hand $inex value is also coming from form dropdown. $options = array( 'Income' =>'Income', 'Expense' =>'Expense', ); echo "<td>" . form_dropdown('inex',$options) ."</td>"; Now, if i do a search between two dates, i have to use Income or Expense values. But, I need the third option in the options array so that i can also choose both so that i can see both income and expenses between these two dates. I think there is a simple answer for that but somehow i cant figure it out. helps are appreciated. thanks in advance. Edited October 9, 2012 by pntyhs Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 9, 2012 Share Posted October 9, 2012 What is the problem? You don't have a third value in the dropdown, just add one, then check for that value and if it is set to "both" or whatever you choose, then don't include that column in the query. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 9, 2012 Share Posted October 9, 2012 "SELECT * FROM my_account WHERE inex='$inex' AND type='$type' AND somedate BETWEEN '$date1' AND '$date2' " Quote Link to comment Share on other sites More sharing options...
pntyhs Posted October 9, 2012 Author Share Posted October 9, 2012 Hi, thanks for the quick reply. I have edited the query, by mistake i pasted here wrong. Anyways my problem here what should i put the third value so that i can choose both value. In this version, I can choose Income or Expense but no the both. I need my search results to deliver me both. thanks. Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 9, 2012 Share Posted October 9, 2012 What is the problem? You don't have a third value in the dropdown, just add one, then check for that value and if it is set to "both" or whatever you choose, then don't include that column in the query. Like I said...add an option for both, then check for it. Logic. It works. Quote Link to comment Share on other sites More sharing options...
pntyhs Posted October 9, 2012 Author Share Posted October 9, 2012 The question is how can i add that option? Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 9, 2012 Share Posted October 9, 2012 $options = array( 'Income' =>'Income', 'Expense' =>'Expense', ); echo "<td>" . form_dropdown('inex',$options) ."</td>"; Are you seriously asking how to add a THIRD OPTION to this list? Quote Link to comment Share on other sites More sharing options...
pntyhs Posted October 9, 2012 Author Share Posted October 9, 2012 my question is not that . it is what should be the third option so that it will include both options. Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 9, 2012 Share Posted October 9, 2012 Whatever you want. You'll have to write logic that controls whether or not the column is included in the query. Your logic will check that value. It's not automatic, you have to actually write the code yourself. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 9, 2012 Share Posted October 9, 2012 my question is not that . it is what should be the third option so that it will include both options. You don't include both options. You completely omit that column from the WHERE clause in the event all values are required Quote Link to comment Share on other sites More sharing options...
pntyhs Posted October 9, 2012 Author Share Posted October 9, 2012 I didnt understand anything at all. can you explain it clearly Quote Link to comment Share on other sites More sharing options...
pntyhs Posted October 9, 2012 Author Share Posted October 9, 2012 Hi Barand. Thank. I know it works like that but i like the put that in in the options. In this way i can choose to search only Income, or only Expense or Both. Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 9, 2012 Share Posted October 9, 2012 Add a third option to the list. Write code that checks if the value submitted is equal to whatever you have named the third option. If the value is equal, then don't add the column inex to the query. If it is NOT that third option, add that column with the chosen option. Try to write some code and then we can help you fix it if it still doesn't work. Post the code you've written, including the part that creates the query. Quote Link to comment Share on other sites More sharing options...
pntyhs Posted October 9, 2012 Author Share Posted October 9, 2012 Thanks Jessica, That did the trick. I have added the third option; 'Both' => 'Both' and created the logic saying that if input value is 'Both' then do the normal query which will choose all. and else the same query above. I somehow thought that there must be a way of adding only one option will do it. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.