I have working search for a created wp_list_table. But i like to know how I can search in more than one column.

My current my working search setup in a Visitor class

//search something
$searchcol= array(
$search = !empty($_REQUEST["s"]) ?  mysql_real_escape_string($_REQUEST["s"]) : '';
//$search = preg_replace( "^$\**(.*)\**$?#", "*$1*", $_REQUEST["s"] );
if(!empty($_REQUEST["s"])) {$query .= ' WHERE '.$searchcol[1].' LIKE "%'.$search.'%"';}

here I just searching in the visitorName column, but i like to use the $searchcol to search in.

A foreach loop

foreach( $searchcol as $col) {
    if(!empty($_REQUEST["s"])) {$query .= ' WHERE '.$col.' LIKE "%'.$search.'%"';}

didn't work


Ok i see my WHERE mistake

I made this working solution doesn't look pretty

$i =0;
        foreach( $searchcol as $col) {
            if($i==0) {
                $sqlterm = 'WHERE';
            } else {
                $sqlterm = 'OR';
            if(!empty($_REQUEST["s"])) {$query .=  ' '.$sqlterm.' '.$col.' LIKE "%'.$search.'%"';}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.