dongtan9066 2016-03-17 06:50
浏览 34
已采纳

在许多表格php中搜索通配符

please help me, i want to make search query but list of table is not shown in php but it work in mysql..here is my code

//$sql = "SELECT * FROM table_name WHERE 1=1" work perfectly
$sql = "SELECT a.* FROM (SELECT table_name FROM information_schema.tables WHERE table_schema like 'rft%') a where 1=1";

if( !empty($requestData['search']['value']) ) 
{   // if there is a search parameter, $requestData['search']['value'] contains search parameter

//search based on input 
$sql.=" AND ( Code LIKE '".$requestData['search']['value']."%' ";    
$sql.=" OR Year LIKE '".$requestData['search']['value']."%' )";
}
 //start search after input 
 $query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");

 $totalFiltered = mysqli_num_rows($query); 

continue here

 // when there is a search parameter then we have to modify total number filtered rows as per search result. 
 $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";

 /* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc  */   
 $query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");

$data = array();
while( $row=mysqli_fetch_array($query) ) 
{  // preparing an array
$nestedData=array(); 

$nestedData[] = $row["Type"];
$nestedData[] = $row["Code"];
$nestedData[] = $row["Year"];

$data[] = $nestedData;
}
  • 写回答

1条回答 默认 最新

  • douchuituo3032 2016-03-17 07:38
    关注

    You only select table_name from information_schema.tables and later you do your WHERE code=.... There is no Code in the result of your select, so this can't work.

    If I get correctly what you are trying to do you have to do it in two steps like this:

    // get all table names:
    $tquery = mysqli_query($conn, "SELECT table_name FROM information_schema.tables WHERE table_schema like 'rft%'");
    while ($table = mysqli_fetch_array($tquery)) {
        // do your query per table
        $sql  = "SELECT * FROM " . $table['table_name'] . " WHERE ( Code LIKE '".$requestData['search']['value']."%' ";
        $sql .=" OR Year LIKE '".$requestData['search']['value']."%' )";
        $query = mysqli_query($conn, $sql);    
        while ( $row = mysqli_fetch_array($query) ) {
            // do what you want with $row
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?