Search a whole table in mySQL for a string

后端 未结 8 1618
孤城傲影
孤城傲影 2020-12-14 01:13

I\'m trying to search a whole table in mySQL for a string.

I want to search all fields and all entrees of a table, returning each full entry that contains the speci

8条回答
  •  再見小時候
    2020-12-14 01:54

    A PHP Based Solution for search entire table ! Search string is $string . This is generic and will work with all the tables with any number of fields

    $sql="SELECT * from client_wireless";
    $sql_query=mysql_query($sql);
    $logicStr="WHERE ";
    $count=mysql_num_fields($sql_query);
    for($i=0 ; $i < mysql_num_fields($sql_query) ; $i++){
     if($i == ($count-1) )
    $logicStr=$logicStr."".mysql_field_name($sql_query,$i)." LIKE '%".$string."%' ";
    else
    $logicStr=$logicStr."".mysql_field_name($sql_query,$i)." LIKE '%".$string."%' OR ";
    }
    // start the search in all the fields and when a match is found, go on printing it .
    $sql="SELECT * from client_wireless ".$logicStr;
    //echo $sql;
    $query=mysql_query($sql);
    

提交回复
热议问题