Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SQL表中的多维数组_Php_Mysql_Arrays_Multidimensional Array - Fatal编程技术网

Php SQL表中的多维数组

Php SQL表中的多维数组,php,mysql,arrays,multidimensional-array,Php,Mysql,Arrays,Multidimensional Array,以下是my SQL表: order_id | product_id | deal_title | currency_code | total | date_modified 我的问题是如何在PHP中创建如下所示的数组: Array ( [product_id_num1] => Array ( [order_id] [deal_title] [currency_code]

以下是my SQL表:

order_id | product_id | deal_title | currency_code | total | date_modified
我的问题是如何在PHP中创建如下所示的数组:

Array
(
    [product_id_num1] => Array
        (
            [order_id]
            [deal_title]
            [currency_code]
            [total]
            [date_modified]
        )
    [product_id_num2] => Array
        (
            [order_id]
            [deal_title]
            [currency_code]
            [total]
            [date_modified]
        )
    [product_id_num3] => Array
        (
            [order_id]
            [deal_title]
            [currency_code]
            [total]
            [date_modified]
        )
etc....
)

谢谢

您可以尝试下面的方法

$arr = array();
while($row = mysqli_fetch_assoc($query_result)) {
    $id = $row['product_id'];
    unset($row['product_id']);
    $arr[$id] = $row;
}

你知道如何用暴力的方式来做吗?@EatCodePlaySleep:你是在使用
mysqli\u*
还是
mysql\u*
函数?它显示的错误是什么?如果没有抛出错误,请在while块之后使用
print\r($arr)
,以了解
$arr
arraynice的结构!现在开始工作了。只是忘记了一个语法。:)