Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Using the “LIKE” with the “=” criterion together

$
0
0

Hi all,

 

I wish I could use the mysqli/ PDO to accomplish what I am trying to do right away. I do not know either how I can intergrate the "=" criteria with the "LIKE" in the following piece of code.

 

The code is for searching with multiple criterion. The search with this cat_id is okey expect that I want its criteria not to be part of the "LIKE" criteria; instead it should be "=" so that I can get the exact match in the search, since cat_id is saved as a foreign key in the child table. May be some form of switch but how?

$criteria = array('ctitle', 'csubject', 'creference', 'cat_id', 'cmaterial', 'ctechnic', 'cartist', 'csource', 'stolen');
$likes = "";
$url_criteria = '';
foreach ( $criteria AS $criterion ) {
        if ( ! empty($_POST[$criterion]) ) {
                $value = ($_POST[$criterion]);
                $likes .= " AND `$criterion` LIKE '%$value%'";
                $url_criteria .= '&'.$criterion.'='.htmlentities($_POST[$criterion]);
        } elseif ( ! empty($_GET[$criterion]) ) {
                $value = mysql_real_escape_string($_GET[$criterion]);
                $likes .= " AND `$criterion` LIKE '%$value%'";
                $url_criteria .= '&'.$criterion.'='.htmlentities($_GET[$criterion]);
        } //var_dump($likes);
}
$sql = "SELECT * FROM collections WHERE c_id>0" . $likes . " ORDER BY c_id ASC";

Your help will be appreciated.

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles