josephbupe Posted April 20, 2013 Share Posted April 20, 2013 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 https://forums.phpfreaks.com/topic/277168-using-the-%E2%80%9Clike%E2%80%9D-with-the-%E2%80%9C%E2%80%9D-criterion-together/ Share on other sites More sharing options...
jugesh Posted April 20, 2013 Share Posted April 20, 2013 print the query first den run it through phpmyadmin You will get to know. You can use Like and = together in same query Link to comment https://forums.phpfreaks.com/topic/277168-using-the-%E2%80%9Clike%E2%80%9D-with-the-%E2%80%9C%E2%80%9D-criterion-together/#findComment-1425926 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.