我想从我的数据库表中获取这样的报告。通过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