我正在用 Json 传递公司信息,我也想用相同的方法传递这些区域,但是有些地方不太好,有人可以帮我吗?
if($_GET['method']=="get_all_companies"){
$query = "SELECT company.id as c_id, company.c_name as c_name, company.c_desc as c_desc,company.c_address as c_address FROM company";
$result = mysql_query($query);
if($result){
$query_areas = "SELECT company.id as c_id, bussiness_area.* FROM company
LEFT JOIN company_area
ON company_area.id_company = company.id
LEFT JOIN bussiness_area
ON bussiness_area.id = company_area.id_area
WHERE company_id = c_id";
$result_areas = mysql_query($query_areas);
$return_arr = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$areas_arr = array();
while ($row2 = mysql_fetch_array($result_areas, MYSQL_ASSOC)) {
$row_array['c_id'] = $row['c_id'];
$row_array['c_name'] = $row['c_name'];
$row_array['c_desc'] = $row['c_desc'];
$row_array['c_address'] = $row['c_address'];
$row_array['bu_title'] = $row2['bu_title'];
array_push($return_arr,$areas_arr,$row_array);
}
}
echo json_encode($return_arr, $areas_arr);
}
else
{
echo json_encode(array('error' => 'true'));
}
}