删除php-mysql结果行中的重复字段

时间:2013-02-24 00:14:03

标签: php mysql

在我执行查询并循环结果以组成记录数组后,当我var_dump该数组时,我看到以下内容:

array
  0 => 
    array
      0 => string '1'
      'id' => string '1'
      1 => string 'record one'
      'name' => string 'record one'
  1 => 
    array
      0 => string '2'
      'id' => string '2'
      1 => string 'record two'
      'name' => string 'record two'

如何将上述内容转化为以下内容?

array
  0 => 
    array
      'id' => string '1'
      'name' => string 'record one'
  1 => 
    array
      'id' => string '2'
      'name' => string 'record two'

2 个答案:

答案 0 :(得分:2)

请勿使用mysql_fetch_array()。使用mysql_fetch_assoc()。 (或者Mysqli等价物)

答案 1 :(得分:1)

使用...

从数据库中获取数据
     $row = mysql_fetch_assoc($result) // <--- _assoc!
相关问题