php和javascript交互:传递数组

<?php
	$mysqli = new mysqli('localhost','root','root','datbas');
	$sql = "select * from itg1 order by pv desc ,uv desc limit 10";
	$result = $mysqli->query($sql);
	$host = array();
	$pv = array();
	$uv = array();
	while($row = $result->fetch_assoc()){
		$host[] = $row['host'];
		$pv[] = intval($row['pv'])/1000000;  //百万
		$uv[] =intval($row['uv'])/10000;  //万
		//echo $row['host']."|".$row['pv']."|".$row['uv']."<br/>";
		
	}
	//var_dump($host);
	//echo "<br/>"."<br/>";
	//var_dump($pv);
	//echo "<br/>"."<br/>";
	//var_dump($uv);
	//$hostj = json_encode($host);
	//$pvj = json_encode($pv);
	//$uvj = json_encode($uv);

?>
<html>
<head>
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
   <script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
   <script>
	var hostj = <?php echo json_encode($host)?>;
	var pvj = <?php echo json_encode($pv)?>;
	var uvj = <?php echo json_encode($uv)?>;
	/*for(i in pvj){
		alert(i);
		alert(pvj.i);
	}*/
	$(function (){
	    $('#container').highcharts({
	        chart: {
	            type: 'column'
	        },
	        title: {
	            text: 'Traffic of the Top 10 Websites in China'
	        },
	        xAxis: {
	            categories: hostj
	        },
	        yAxis: {
	            title: {
	                text: 'visit'
	            }
	        },
	        series: [{
	            name: 'pv(百万)',
	            data: pvj
	        }, {
	            name: 'uv(万)',
	            data: uvj
	        }]
	    });
	});
   </script>
</head>
	
<body>
   <div id="container" style="min-width:800px;height:400px;"></div>
</body>
</html>



你可能感兴趣的:(php和javascript交互:传递数组)