我想從我的數據庫表中獲取這樣的報告。通過php生成報告
事情做報告時,應該考慮是:
- 報告將基於所選擇的日期。
兩臺數據庫和兩個表(已加入)「公告」和「客戶」
展廳有showroom_name每個都在客戶
表相關的記錄。一個展廳可能每天都有幾個客戶詢問。在一天中可能會有來自每個展廳的查詢數量。
假設一個月的第一天5查詢應該出現在日期欄下面和特定展廳名稱前面 。
我的查詢從兩個表中選擇數據工作正常。
SELECT
abans_crm.customers.added_date,
abans_crm.customers.location_id
FROM
abans_crm.customers
INNER JOIN sh_sso.showrooms ON sh_sso.showrooms.showroom_id = abans_crm.customers.location_id
WHERE
abans_crm.customers.added_location = -99 AND
abans_crm.customers.type_id = 1
ORDER BY
abans_crm.customers.location_id ASC
查詢結果
,我被打上兩個數據有兩個不同的日期。 2016-02-09和2016-02-23。 '356'是showroom_id,那麼報告的第9列成爲1,第23天的列成爲1.希望你明白我的觀點。我如何計算每個展廳的查詢數量?
赫斯的代碼片段,我至今寫。不知道你是否需要更多詳細信息,請在下面評論寫事後
<?php
echo $row->showroom_name;
$conn = mysql_connect('localhost', 'root', '[email protected]') or die("Unable to connect to MySQL");
mysql_select_db('sh_sso', $conn);
mysql_select_db('abans_crm', $conn);
$query_3 = "SELECT
abans_crm.customers.added_date,
abans_crm.customers.location_id
FROM
abans_crm.customers
INNER JOIN sh_sso.showrooms
ON sh_sso.showrooms.showroom_id = abans_crm.customers.location_id
WHERE
abans_crm.customers.added_location = -99 AND
abans_crm.customers.type_id = 1
ORDER BY
abans_crm.customers.location_id ASC";
$retval = mysql_query($query_3);
if(!$retval) {
die('Could not get data: ' . mysql_error());
}
$select_month = '2';
$select_year = '2016';
$days = cal_days_in_month(CAL_GREGORIAN,$select_month,$select_year);
while ($row2 = mysql_fetch_assoc($retval)){
$year = date('Y',strtotime($row2['added_date']));
$month = date('m',strtotime($row2['added_date']));
$date = date('m',strtotime($row2['added_date']));
$showroom_id = $row2['location_id'];
if($year == $select_year && $month == $select_month){
for($a = 1; $a <= $days; $a++){
echo "<td id=".$a.">".$count."</td>";
}
}
}
?>
。
客戶表中的字段 cu_id
,cu_name
,cu_email
,cu_address
,cu_phone
,cu_remark
,added_date
,last_update
,added_by
,status_id
,location_id
,cu_nic
,cu_age
,cu_occ
,cu_land
,purchase_type
,pref_model
,pref_color
,oth_model
,purchase_date
, currenrt_bike
,bike_year
,att_by
,cu_made
, about_hero
,source_id
,added_ip
,dealer_flag
,added_location
,cur_milage
,cat_id
,type_id
公告表字段 showroom_id
,showroom_code
,showroom_name
,showroom_address
,address_city
,manager_name
,manager_mobile
,manager_id
,shop_email
,shop_phone
,shop_fax
,showroom_type
,added_date
,last_update
,added_by
,status_id
,level_id
謝謝。
如果提供你的問題的SQL撥弄它是我們更容易嘗試的東西: http://sqlfiddle.com/ – Jester
您的訂單添加日期BY子句。其餘的將在PHP中完成。 – Strawberry