doushan6161 2013-05-06 18:35
浏览 10

SQL结果作为PHP数组

I am trying to solve this. Maybe this is absolutly incorrect, I need some help.

I have a table like this:

INSERT INTO `municipios` (`id`, `provincia`, `municipio`) VALUES (1, 1, 'Alegría-Dulantzi'), (2, 1, 'Amurrio'), (3, 1, 'Añana'), (4, 1, 'Aramaio'), (5, 1, 'Armiñón'),

And this is my handler:

    $query = "SELECT * FROM municipios WHERE provincia='1'";
$result = mysql_query($query);      
while ($row = mysql_fetch_array($result)) {                 
    $groups = array(
    $row{'id'} => array(
        'name' => $row{'municipio'},
        'description' => 'Agrupación electoral de ' . $row{'municipio'},
        'status' => 'public',
        'enable_forum' => 1,
        ),
        );
}

With this I got just the last result. I have tried another options, but doesn´t work.

  • 写回答

2条回答 默认 最新

  • druhoytza979667566 2013-05-06 18:46
    关注

    Is this an issue with the way you're appending the groups array? I think your overwriting the array every time u set a value. Try using array_push() to append to groups.

    Let us know of that helps!

    array_push() http://php.net/manual/en/function.array-push.php

    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答