Correct way to record multiple parameter lookups

Belove is my search term, which works great if I want any of the search value passed through, but what if I want an exact match for a specific value?

I can use the operator AND

, but that will increase the number of lines, for example how can I write a query if I want a particular location

match, pls can someone help me with a better search query enter image description here

            $sql = "SELECT * ";
            $sql .= "FROM js_projects WHERE ";
            $sql .= "jsp_title LIKE '%" . $valToSearch . "%' ";
            $sql .= "OR jsp_nature LIKE '%" . $nature . "%' ";
            $sql .= "OR jsp_etype LIKE '%" . $etype . "%' ";
            $sql .= "OR jsp_location LIKE '%" . $location . "%' ";
            $sql .= "OR jsp_date LIKE '%" . $jobdate . "%' ";

      

Edit

Suppose I have a value for

  • valtosearch, location, jobdate, etype and I want an exact match for all these values,

  • or I can have any two of these values ​​and I want them to match exactly,

  • or I can get any of these values ​​and I want it to be accurate.

So how can I write a query for all these possibilities?

+3


source to share


1 answer


Try it. This will work fine



$condition=($location!=''?" AND jsp_location LIKE '%".$location."%":"");
$condition.=($jobdate!=''?" AND jsp_date LIKE '%".$jobDate."%":"");
$sql = "SELECT * FROM js_projects WHERE jsp_title LIKE '%".$valueToSearch."%' ".$condition;

      

0


source







All Articles