如何把mysql 的数据 输出为多维数组,谢谢了!
MYSQL查询的内容大概就是这样子的。不过我想输出为以下这种格式$data=array("province"=>"GD","city"=>"GD_ST","hphm"=>...
MYSQL 查询的内容大概就是这样子的。不过我想输出为以下这种格式
$data=array (
"province" => "GD", "city" => "GD_ST", "hphm" => "粤DJ1491", "hpzl" => "02","lists"=> array(
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
),
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
),
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
)
)
);
大概就是这个样子 展开
$data=array (
"province" => "GD", "city" => "GD_ST", "hphm" => "粤DJ1491", "hpzl" => "02","lists"=> array(
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
),
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
),
array (
"date" => "2012-04-26 05:39:01",
"area" => "澄海区中山莱美路口", "act" => "机动车不按交通信号灯规定通行的", "code" =>"", "fen" => "3", "money" => "200", "handled" => "0"
)
)
);
大概就是这个样子 展开
1个回答
展开全部
<?
$host = "localhost"; //主机名
$user = "root"; //mysql用户名
$password = ""; //mysql密码
$database = "doc"; //mysql数据库名
$tables = "mclass"; //表名
$conn=mysql_connect("$host","$user","$password") or die("数据库打开出错");
mysql_select_db("$database");
$query="select * from $tables";
$result=mysql_query($query,$conn);
$i=0;
$j=0;
while($row=mysql_fetch_row($result)){
$array[$i][$j] = $row[0].$row[1];
$array2[$i][$j] = $row[0];
$j++; // echo $i.",".$j.$row[1]."<br>";
if($j==3) {
$i++;
$j=0;
} //else {$j++ ;}
}
$amax=count($array);//获是数组内数据个数。
$rows=2; //设置列数
//开始显示数据
for ($x=0; $x<=$amax-1; $x++) {
for ($y=0; $y<= $rows; $y++) {
echo "<a href=".$array2[$x][$y].">".$array[$x][$y]."</a>|" ;
}
echo "<p>";
}
/*
显示结果为
aaa|bbb|ccc
ddd|eee|fff
lll|mmm|nnn
.....
*/
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询