How do I store all results from an SQL query in a multidimensional array?

后端 未结 5 1299
心在旅途
心在旅途 2021-02-08 17:46

hello every one i want to convert my array into other array type , plz help me out . I m using this

$row = mysql_fetch_array($result, MYSQL_ASSOC); 
5条回答
  •  走了就别回头了
    2021-02-08 17:57

    $data = array(); // create a variable to hold the information
    while (($row = mysql_fetch_array($result, MYSQL_ASSOC)) !== false){
      $data[] = $row; // add the row in to the results (data) array
    }
    
    print_r($data); // print result
    

    Update Feb '17 Now that it's 2017, it's advised you use PDOs over mysql_*. A lot safer and can return this natively with fetchAll (as shown in `TrexXx's answer).

提交回复
热议问题