JMR JMR - 4 months ago 9
SQL Question

How to add many fields to search button for the below query-wordpress

i am unable to add many fields for the search button query

The search query should be based on name OR application_id OR company OR country.

if i search based on any of the criteria it should give me the result.

Below is my code

SELECT * FROM $table_name WHERE name LIKE %s ORDER BY $orderby $order LIMIT %d OFFSET %d",'%'.$_POST['s'].'%',$per_page, $paged


Tried:

SELECT * FROM $table_name WHERE name LIKE %s OR Application_ID LIKE %s OR Country LIKE %s ORDER BY $orderby $order LIMIT %d OFFSET %d",'%'.$_POST['s'].'%',$per_page, $paged....


But Ended Up with no result.

Answer

You also have to pass the parameter multiple times:

"SELECT * FROM $table_name WHERE name LIKE %s 
    OR Application_ID LIKE %s OR Country LIKE %s 
ORDER BY $orderby $order 
LIMIT %d OFFSET %d", '%'.$_POST['s'].'%', '%'.$_POST['s'].'%',
    '%'.$_POST['s'].'%', $per_page, $paged
Comments