php opencart 2.1.0.1 mysql查询错误: mysql_num_fields() expects parameter 1 to be resource object given in

标签 php mysql opencart2.x

我在 mysql 中遇到问题,任何人都可以帮助我解决这个问题。 问题:mysql_num_fields() 期望参数 1 是 (opencart 2.1.0.1) 中给定的资源对象

最佳答案

公共(public)函数导出(){

    $output = "";

    $table = "app_feedback"; // Enter Your Table Name 


  $query = "SELECT ap.*,sr.name as ShowRoomName,CONCAT_WS(' ', sr.address1, sr.address2,sa.showroom_area_name,sc.showroom_city_name,ss.showroom_state_name,'-',sr.pincode) AS ShowroomAddress FROM ".DB_PREFIX."app_feedback ap LEFT JOIN " . DB_PREFIX . "showroom sr ON (ap.showroom = sr.showroom_id) LEFT JOIN " . DB_PREFIX . "showroom_area sa ON (sr.showroom_area_id = sa.showroom_area_id) LEFT JOIN " . DB_PREFIX . "showroom_city sc ON (sr.showroom_city_id = sc.showroom_city_id) LEFT JOIN " . DB_PREFIX . "showroom_state ss ON (sr.showroom_state_id = ss.showroom_state_id)";

    if(!empty($this->request->get['date_from'])&&!empty($this->request->get['date_to'])){

        $date_from = $this->request->get['date_from'];

        $date_to = $this->request->get['date_to'];

        $time_from = $this->request->get['time_from'];

        if(empty($time_from)){

           $time_from = '00:00';

        }

        $time_to = $this->request->get['time_to'];

        if(empty($time_to)){

           $time_to = '23:59';

        }

//      $query .=" WHERE DATE(date)>= '".$date_from."' AND DATE(date)<='".$date_to."'";

        $query .=" WHERE date BETWEEN '".$date_from. ' '.$time_from.":00' AND '".$date_to.' '.$time_to.":00'";

    }

    $sql = mysql_query($query);

    $columns_total = mysql_num_fields($sql);

    // Get The Field Name

    for ($i = 0; $i < $columns_total; $i++) {

    $heading = mysql_field_name($sql, $i);

    if($heading!='showroom')

    {

      $output .= '"'.$heading.'",';

    }

//  $output .= '"'.$heading.'",';

    }
    $output .="\r\n";
    // Get Records from the table
    while ($row = mysql_fetch_array($sql)) {

    for ($i = 0; $i < $columns_total; $i++) {

//  $output .='"'.$row["$i"].'",';

    if($i!=16){

        $values=str_replace('amp;', "", $row["$i"]);

        $output .='"'.$values.'",'; 

    }

    }

    $output .="\r\n";

    }

    // Download the file



    $filename = "feedback.csv";

    header('Content-type: application/csv');

    header('Content-Disposition: attachment; filename='.$filename);

    echo $output;

}

关于php opencart 2.1.0.1 mysql查询错误: mysql_num_fields() expects parameter 1 to be resource object given in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37359373/

相关文章:

php - 将 $_GET 传递给 mySQL 查询

PHP ↔ Perl 接口(interface)或绑定(bind)

java - 通过应用程序上下文配置 session 工厂,连接已初始化,但 session 工厂始终指向 null

c# - SQL Server 条件连接

php - 如何在没有货币符号的情况下获取价格值?

php - opencart 2.x 中产品页面的自定义 SEO URL

php - 使用 session_regenerate_id(true) 后 session 终止

javascript - 使用 .php MySQL 添加自定义 .png 标记到 map

mysql - SQL:从另一个数据集添加多列

json - opencart 2.0 SyntaxError : JSON. 解析:JSON 数据第 1 行第 1 列的数据意外结束 OK