我在 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/