php代码翻译成java代码
将下面的php代码翻译成java代码,生成json即可,谢谢啦。这个是sql查询出来的结果这个是需要生成的json格式$g_source_type=array("0"=>...
将下面的php代码翻译成java代码,生成json即可,谢谢啦。
这个是sql查询出来的结果
这个是需要生成的json格式
$g_source_type = array("0"=>"资讯","1"=>"论坛","2"=>"贴吧","3"=>"博客","4"=>"微博");
$init_data = array();
foreach($g_source_type as $key => $val) $init_data[$key] = array("name"=>$val,"total"=>0);
$init_data["all"] = array("name"=>"全部","total"=>0);
$start_day = date("Y-m-d",time()-7*24*60*60);
$end_day = date("Y-m-d",time());
$sql = "select sourcetype,DATE(release_date) rd,count(id) as total from ".TABLE_DATA." where release_date between '".$start_day." 00:00:00' and '".$end_day." 23:59:59' and filtered=1 group by sourcetype,rd";
$receive_data = $this->db->select_list_table($sql);
if(!$receive_data) die(json_encode(array("result"=>false,"err"=>"无相关数据")));
$ret = array();
foreach($receive_data as $data){
if(!isset($ret[$data["rd"]])) $ret[$data["rd"]] = $init_data;
if(isset($g_source_type[$data["sourcetype"]])) $ret[$data["rd"]][$data["sourcetype"]]["total"] = $data["total"];
$ret[$data["rd"]]["all"]["total"] += $data["total"];
}
echo json_encode(array("result"=>true,"data"=>$ret)); 展开
这个是sql查询出来的结果
这个是需要生成的json格式
$g_source_type = array("0"=>"资讯","1"=>"论坛","2"=>"贴吧","3"=>"博客","4"=>"微博");
$init_data = array();
foreach($g_source_type as $key => $val) $init_data[$key] = array("name"=>$val,"total"=>0);
$init_data["all"] = array("name"=>"全部","total"=>0);
$start_day = date("Y-m-d",time()-7*24*60*60);
$end_day = date("Y-m-d",time());
$sql = "select sourcetype,DATE(release_date) rd,count(id) as total from ".TABLE_DATA." where release_date between '".$start_day." 00:00:00' and '".$end_day." 23:59:59' and filtered=1 group by sourcetype,rd";
$receive_data = $this->db->select_list_table($sql);
if(!$receive_data) die(json_encode(array("result"=>false,"err"=>"无相关数据")));
$ret = array();
foreach($receive_data as $data){
if(!isset($ret[$data["rd"]])) $ret[$data["rd"]] = $init_data;
if(isset($g_source_type[$data["sourcetype"]])) $ret[$data["rd"]][$data["sourcetype"]]["total"] = $data["total"];
$ret[$data["rd"]]["all"]["total"] += $data["total"];
}
echo json_encode(array("result"=>true,"data"=>$ret)); 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |