Adding database results to array

后端 未结 1 454
盖世英雄少女心
盖世英雄少女心 2021-01-05 13:39

I am having a mental blank here and cannot for the life of me figure out a solution.

My scenario is that I am programming in PHP and MySQL. I have a database table r

相关标签:
1条回答
  • 2021-01-05 13:57

    You should do something like this:

    $data = array();
    while($row = $db->database_fetch_assoc($query))
    {
        $data[] = $row;
    }
    

    Now $data is an array where each element is a row of the query result.

    Then you can access the rows as $data[0], $data[1], and the elements within the rows as $data[1]['package'], $data[0]['itemtype'], because each row is an associative array.

    You can get the number of rows returned using count($data).

    0 讨论(0)
提交回复
热议问题