Jump to content

Where if else cancel


ayok

Recommended Posts

Hi,

I'm trying to use if in mysql query, but can't get it work.

So the case is i want to select rows when siteid is not zero, if it's zero then I need to cancel the where.

I've tried

SELECT * FROM items WHERE IF(siteid > 0,$siteid,0) = $siteid

With this query I got good result when $siteid is not 0, but it returns empty when $siteid = 0, which actually select siteid = 0. What I need is no more where, so it should just returns all.

 

Could anybody help me here?

 

Thanks

ayok

Link to comment
https://forums.phpfreaks.com/topic/262168-where-if-else-cancel/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.