【问题标题】:mysql_fetch_array and only string array keysmysql_fetch_array 并且只有字符串数组键
【发布时间】:2011-09-16 05:28:02
【问题描述】:

当我尝试 print_r mysql_fetch_array 的 sql 查询时,我得到了这个结果。

Array
(
    [0] => 1
    [id] => 1
    [1] => 2011
    [publish_date] => 2011
    [2] => Posted
    [status] => Posted
    [3] => test
    [post_title] => test
    [4] =>  testy test test testtttttt
    [post_text] =>  testy test test testtttttt
    [5] => true
    [post_comments] => true
    [6] => 21
    [reviews] => 21
    [7] => 1
    [network_id] => 1
    [8] => 3
    [views] => 3
    [9] => 0
    [comments] => 0
)

我想要的只是字符串数组键,那么我怎样才能将这个结果转换成那个呢?

Array
(
    [id] => 1
    [publish_date] => 2011
    [status] => Posted
    [post_title] => test
    [post_text] =>  testy test test testtttttt
    [post_comments] => true
    [reviews] => 21
    [network_id] => 1
    [views] => 3
    [comments] => 0
)

【问题讨论】:

    标签: php mysql arrays


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      使用 mysql_fetch_assoc 代替 mysql_fetch_array。 就是这样。

      【讨论】:

        【解决方案3】:

        使用mysql_fetch_assoc函数

        使用mysql_fetch_array函数的第二个参数:MYSQL_ASSOC

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-06-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-06-08
          • 1970-01-01
          相关资源
          最近更新 更多