Jump to content

Where Input Value Or All


pntyhs

Recommended Posts

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 by pntyhs
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.