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 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路