Jump to content

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


josephbupe
Go to solution Solved by jugesh,

Recommended Posts

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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