wyh9405
2017-03-31 02:36
采纳率: 40%
浏览 5.0k

php 数据库拿到数据放到数组


<?php
$conn=mysqli_connect("localhost","root","","test") or die("error connecting") ; //连接数据库
$query = "select * from bg_cate cate";
$result = mysqli_query($conn,$query);
$data = array();
//var_dump ($result);
while ($rows= mysqli_fetch_array($result))
{
$data[] = $rows;

}

?>


我用的方法是这个,但是我理想中的获取的数组应该是这样的:
Array
(
[0] => Array
(
[cate_Id] => 4
[cate_ParentId] => 0
[cate_Name] => 往事如风
[cate_Intro] => 记录往事
[cate_Order] => 0
[cate_Icon] => icons/6.gif
)

但是实际中是这样的:
Array
(
[0] => Array
(
[0] => 4
[cate_Id] => 4
[1] => 0
[cate_ParentId] => 0
[2] => 往事如风
[cate_Name] => 往事如风
[3] => 记录往事
[cate_Intro] => 记录往事
[4] => 0
[cate_Order] => 0
[5] => icons/6.gif
[cate_Icon] => icons/6.gif
)

求大神指教,我怎样才能拿到我靠理想中的那种数组。感激不尽

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题