dongzhuo5425 2015-04-10 03:12
浏览 130

PHP mysqli_fetch_assoc存储到一个数组中

I am having troubles pulling a row from sql query and storing it into an array. Here is my code.

$sql = "SELECT water, importdate
        FROM customer_table
        WHERE customer_number = '" . $custNum . "';";
        $result_of_login_check = $this->db_connection->query($sql);
        echo $sql . "<br>";
        $result = mysqli_query($this->db_connection,$sql);

        // set array
        $array = array();

        // look through query
        while($row = mysqli_fetch_assoc($result)){

        // add each row returned into an array
        $array[] = $row;
        }
        print_r($array);

This is what the output looks like when I print the array,

Array ( 
    [0] => Array ( 
        [water] => 23 
        [importdate] => 2014-03-29 
    ) 
    [1] => Array ( 
        [water] => 33 
        [importdate] => 2015-02-22 ) 
    )

While it is storing, I am stuck at trying to figure out how to copy each row into the array so it looks like this,

Array ( 
    [water] => 23 
    [importdate] => 2014-03-29
) 
Array ( 
    [water] => 33 
    [importdate] => 2015-02-22
)

Which is each row stored in $row.

What I am going for is that I need to pull a list of bill amount and dates from the same customer from my database and then display each month by date. Showing the current months bill.

Thanks for your help!

  • 写回答

2条回答 默认 最新

  • douyicao2199 2015-04-10 03:29
    关注

    Who is containing the objects when you say?

    Array ( 
        [water] => 23 
        [importdate] => 2014-03-29
    )
     Array ( 
        [water] => 33 
        [importdate] => 2015-02-22
    )
    

    Nothing.. You need to have an array containing this arrays, or you need to have multiple arrays indexed somewhere, what is basically an array with arrays. So nothing wrong with that format..

    Why you need this format specifically? It doesn't make sense..

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算