Jump to content

Recommended Posts

Hi,

 

I want to select all from my database where the months column is set to '24 Month'

and also set to ''.

 

SELECT * FROM csv_item WHERE item_contract_length='' && item_contract_length='24 Month'

 

However, every time I try it, it just brings back no results, even though both of them work on there own.

 

Any ideas please, as I really stuck.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/185361-simple-sql-not-working/
Share on other sites

Thanks for your help

 

OR will not work.

 

What i'm trying to do is;

In the database there are 5 options in the column - '', '6 Month', '12 Month', '24 month', '36 Month'

 

I have a dropdown list that has all of the options apart from the blank one.

If the field is empty, I want it to select the selected option i.e 24 Month AND all rows that have a black field

 

Other wise, all rows that are black will never show up in the list.

 

 

Here is the full code:

SELECT * FROM csv_item WHERE item_group='$iSearch' && item_network='$netSearch' && item_contract_length='' && item_contract_length='$clSearch' ORDER by item_internal_name AS

 

 

Any more ideas would be a great help.

:)

 

I guess you know better. Did you try at least?

http://en.wikipedia.org/wiki/Boolean_logic

 

SELECT * FROM csv_item WHERE item_group='$iSearch' AND item_network='$netSearch' AND (item_contract_length='' OR item_contract_length='$clSearch' OR item_contract_length IS NULL) ORDER by item_internal_name AS

 

Thanks for your help guys.

 

Thia is the final block of code.

It was item_contract_length IN('','$clSearch') that I was after.

 

$item_sql = "SELECT * FROM csv_item WHERE item_group='$iSearch' && item_network='$netSearch' && item_contract_length IN('','$clSearch') ORDER by item_internal_name ASC";

 

 

I needed to select both black AND month at the same time.

 

:)

Did you try the query I posted? It would work just as well.

You can't have a row that is blank AND '24 month' long at one time.

You need to select all rows that are '24 month' long OR blank

 

You can consider IN() as alternate syntax for OR (this simplifies things a little, but for this example that's irrelevant)

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.