在做的一个项目需要统计一些数据,这里模拟插入10000数据。
其中数据包括经纬度(app上传上来的),这里要调用百度API获取这个经纬度的身份存起来,供后面调用echarts画全国地图各省份分布的.
这里随机的生成经纬度跟时间,
有些细节处理的不是很好啦,无所谓了,随机插入数据即可。
<?php $link=mysqli_connect("localhost","root","dengli","yilonggu"); $link->query("delete from message"); function suijishijian() { $month=array('0','01','02','03','04','05','06','07','08','09','10','11','12'); $days=array('0','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'); $hour=array('0','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','00'); $fz=array("","00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50","51","52","53","54","55","56","57","58","59"); $day=array( "01"=>"31", "02"=>"28", "03"=>"31", "04"=>"30", "05"=>"31", "06"=>"30", "07"=>"31", "08"=>"31", "09"=>"30", "10"=>"31", "11"=>"30", "12"=>"31"); $y=rand(2010,2013); $m=$month[rand(1,12)]; $d=$days[rand(1,$day["$m"])]; $h=$hour[rand(1,24)]; $mm=$fz[rand(1,60)]; $s=$fz[rand(1,60)]; return "$y-$m-$d $h:$mm:$s\\n"; } function floadNumber($min,$max) { return $min + mt_rand() / mt_getrandmax() * ($max - $min); } function shengfen($jd,$wd) { $url="http://api.map.baidu.com/geocoder?location={$wd},{$jd}&output=json"; $json=json_decode(file_get_contents($url),TRUE); return $json['result']['addressComponent']['province']; } for($i=1;$i<10000;$i++) { $zid=rand(1,99999); $time=suijishijian(); $jingdu=floadNumber(100,120); $weidu=floadNumber(30,40); $province=shengfen($jingdu,$weidu); $lid=rand(1,13); $type=rand(0,3); $tag=rand(1,4); $sbh=md5(time()); $sql="insert into `tongji` (zid,time,jingdu,weidu,province,lid,type,tag,sbh) VALUES ('{$zid}','{$time}','{$jingdu}','{$weidu}','{$province}','{$lid}','{$type}','{$tag}','{$sbh}')"; $link->query($sql); echo $sql."\\n"; } $link->close();?>