php - Search Using IN Condition in MySql -


i writing web services ios in cakephp , stuck in in condition.

i have table dog_temperaments , has values "happy,dependent,shy".

now if ios send me array (happy,shy) search this

select dog_temperaments.* temperaments in(happy,shy)

its work fine if ios send me array 0 or any(means search temperament) how search........

any means search temperaments

if 0 or any no need condition ishould return of them.

so aassuming $type contain temperaments array , 0/any single element case.

if(count($type) == 1 && in_array(($type[0], array('0', 'any'))) {     $condition = ""; } else {     $condition = "where temperaments in ('" . implode("','", $type) . "')"; } 

and query -

"select dog_temperaments.* dog_temperaments ".$condition 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -