php - Using the "LIKE" with the "=" criterion together -


i not know how can intergrate "=" criteria "like" in following piece of code.

the code searching multiple criterion. search cat_id okey expect want criteria not part of "like" criteria; instead should "=" can exact match in search. appreciated.

$criteria = array('ctitle', 'csubject', 'creference', 'cat_id', 'cmaterial', 'ctechnic', 'cartist', 'csource', 'stolen'); $likes = ""; $url_criteria = ''; foreach ( $criteria $criterion ) {         if ( ! empty($_post[$criterion]) ) {                 $value = ($_post[$criterion]);                 switch ($criterion) {                     case 'cat_id':                         $likes .= " , `$criterion`='$value'";                         break;                      default:                         $likes .= " , `$criterion` '%$value%'";                         break;                 $url_criteria .= '&'.$criterion.'='.htmlentities($_post[$criterion]);             } }         } elseif ( ! empty($_get[$criterion]) ) {                 $value = mysql_real_escape_string($_get[$criterion]);                 switch ($criterion) {                     case 'cat_id':                         $likes .= " , `$criterion`='$value'";                         break;                      default:                         $likes .= " , `$criterion` '%$value%'";                         break;                 $url_criteria .= '&'.$criterion.'='.htmlentities($_get[$criterion]);         } //var_dump($likes); }  $sql = "select * collections c_id>0" . $likes . " order c_id asc"; 

switch friend.

$criteria = array('ctitle', 'csubject', 'creference', 'cat_id', 'cmaterial', 'ctechnic', 'cartist', 'csource', 'stolen'); $likes = ""; $url_criteria = ''; foreach ($criteria $criterion) {         if (isset($_post[$criterion]) && !empty($_post[$criterion])) {                 $value = mysql_real_escape_string($_post[$criterion]);                 switch ($criterion) {                     case 'cat_id':                         $likes .= " , `$criterion`='$value'";                         break;                      default:                         $likes .= " , `$criterion` '%$value%'";                         break;                 } 

better'n if statement or ternary operator because it's easy expand in future.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -