Equal and not equal in PHP query

时间:2016-04-04 17:06:26

标签: php mysql wordpress

I need to show a list of exhibits from a database. Some are events (shows lasting only one day), marked with a checkbox. I don't want to include those.

When running my Query without and selector, I get 103 results.

If I add this line

    AND `event`.`meta_value` = 'on'

I get 23 results (the events). It works well.

If I add that line instead

    AND `event`.`meta_value` != 'on'

I get 12 results. They are not events, but it is missing 68 posts.

I also tried using <> instead of != with a similar result.

1 个答案:

答案 0 :(得分:0)

They other 68 posts most likely have NULL as value, you should also be able to see this for yourself if you check the database. They won't show up with = or != ... If you want to see them you'll have to change your query to specifically look for the attribute being NULL:

AND `event`.`meta_value` IS NULL
相关问题