返回省市区接口撰写......登陆

省市区接口撰写文档

phpcn_u887332019-03-03 19:31:42277
function getArea($pid){
	$conn = mysqli_connect('127.0.0.1','root','root','php',3306);

	if(!$conn){
		echo '数据库错误',mysqli_connect_error();
	}

	$sql = "select area_id,area_pid,area_name from php_area where area_pid={$pid}";

	$res = mysqli_query($conn,$sql);

	$data = [];
	while($row=mysqli_fetch_assoc($res)){
		$data[] = $row;
	}
	mysqli_close($conn);
	return json_encode($data);
}
标题:省市区接口文档
地址:http://localhost/test/a.php
传参:int $pid 
返回值:该id下所有下级地区
代码:
function getArea($pid){
$conn = mysqli_connect('127.0.0.1','root','root','php',3306);
 
if(!$conn){
echo '数据库错误',mysqli_connect_error();
}
 
$sql = "select area_id,area_pid,area_name from php_area where area_pid={$pid}";
 
$res = mysqli_query($conn,$sql);
 
$data = [];
while($row=mysqli_fetch_assoc($res)){
$data[] = $row;
}
mysqli_close($conn);
return json_encode($data);
}
返回值示例:
[
    {
        "area_id": "3",
        "area_pid": "2",
        "area_name": "东城区"
    },
    {
        "area_id": "4",
        "area_pid": "2",
        "area_name": "西城区"
    },
    {
        "area_id": "5",
        "area_pid": "2",
        "area_name": "崇文区"
    },
    {
        "area_id": "6",
        "area_pid": "2",
        "area_name": "宣武区"
}
]

QQ图片20181114103819.png

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送