如何使用MySQl明智地显示数据类别

时间:2017-12-09 10:51:44

标签: php mysql

这是我的SQL Fiddle我试图使用此查询在DataTables中显示数据,但是如果我想相应地显示每个品牌和类别的数据。我应该在此查询中更改什么?

$q = intval($_POST['Name']);
$time = strtotime($_POST['Date']);
$day   = date('d',$time);
$month = date('m',$time);
$year  = date('Y',$time);
$query = "
SELECT d.distributor_name
     , s.order_date
     , p.product_name
     , s.nsp
     , s.current_sales
     , s.closing_balance
  FROM sales s
  LEFT 
  JOIN product p
    ON p.product_id = s.product_id
  LEFT 
  JOIN distributor d
    ON s.d_id = d.d_ID
 WHERE MONTH(s.order_date) =  '" . $month . "'  
   AND YEAR(s.order_date) = '" . $year . "' 
   AND d.d_id  = '" . $q . "';
";

$result = $connect->query($query);
$array = array();
while ($row = mysqli_fetch_assoc($result)) {
    $array['data'][] = $row;
}
echo json_encode($array);
$connect->close();

0 个答案:

没有答案