打印php多维数组

打印php多维数组,php,arrays,printing,Php,Arrays,Printing,我正在尝试打印一个数组 第一个例子 $result2 = mysql_query("SELECT ps_product_attribute.id_product_attribute AS attribute_id, ps_advanced_attributes.pack_product_id AS base_product, ps_advanced_attributes.pack_product_qty AS qty_base_product, ps_stock_available.qu

我正在尝试打印一个数组

第一个例子

$result2 = mysql_query("SELECT 
ps_product_attribute.id_product_attribute AS attribute_id, 
ps_advanced_attributes.pack_product_id AS base_product, 
ps_advanced_attributes.pack_product_qty AS qty_base_product, 
ps_stock_available.quantity AS base_product_on_hand, 
FLOOR(ps_stock_available.quantity / ps_advanced_attributes.pack_product_qty) AS available_to_customer 
FROM ps_product_attribute 
JOIN ps_advanced_attributes ON ps_advanced_attributes.attribute_id = ps_product_attribute.id_product_attribute 
JOIN ps_stock_available ON ps_stock_available.id_product = ps_advanced_attributes.pack_product_id 
ORDER BY ps_product_attribute.id_product_attribute ASC, ps_stock_available.quantity DESC");

echo '<pre>';   
WHILE($db_field2 = mysql_fetch_array($result2)){
print_r($db_field2);}
echo  '</pre>';
Array

(

    [0] => 6703
    [attribute_id] => 6703
    [1] => 382
    [base_product] => 382
    [2] => 1
    [qty_base_product] => 1
    [3] => 69
    [base_product_on_hand] => 69
    [4] => 69
    [available_to_customer] => 69
)

Array

(

    [0] => 6703
    [attribute_id] => 6703
    [1] => 103
    [base_product] => 103
    [2] => 1
    [qty_base_product] => 1
    [3] => 4
    [base_product_on_hand] => 4
    [4] => 4
    [available_to_customer] => 4
)
Array
(

    [0] => 6703
    [attribute_id] => 6703
    [1] => 471
    [base_product] => 471
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
Array
(

    [0] => 6704
    [attribute_id] => 6704
    [1] => 103
    [base_product] => 103
    [2] => 1
    [qty_base_product] => 1
    [3] => 4
    [base_product_on_hand] => 4
    [4] => 4
    [available_to_customer] => 4
)
Array
(

    [0] => 6704
    [attribute_id] => 6704
    [1] => 397
    [base_product] => 397
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
Array
(

    [0] => 6704
    [attribute_id] => 6704
    [1] => 465
    [base_product] => 465
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
Array
(

    [0] => 6705
    [attribute_id] => 6705
    [1] => 103
    [base_product] => 103
    [2] => 1
    [qty_base_product] => 1
    [3] => 4
    [base_product_on_hand] => 4
    [4] => 4
    [available_to_customer] => 4
)
Array
(

    [0] => 6705
    [attribute_id] => 6705
    [1] => 533
    [base_product] => 533
    [2] => 1
    [qty_base_product] => 1
    [3] => 2
    [base_product_on_hand] => 2
    [4] => 2
    [available_to_customer] => 2
)
Array
(

    [0] => 6705
    [attribute_id] => 6705
    [1] => 469
    [base_product] => 469
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
Array
(

    [0] => 6706
    [attribute_id] => 6706
    [1] => 395
    [base_product] => 395
    [2] => 1
    [qty_base_product] => 1
    [3] => 41
    [base_product_on_hand] => 41
    [4] => 41
    [available_to_customer] => 41
)
Array
(

    [0] => 6706
    [attribute_id] => 6706
    [1] => 103
    [base_product] => 103
    [2] => 1
    [qty_base_product] => 1
    [3] => 4
    [base_product_on_hand] => 4
    [4] => 4
    [available_to_customer] => 4
)

Array
(

    [0] => 6706
    [attribute_id] => 6706
    [1] => 468
    [base_product] => 468
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
只有这一个结果

例2

正如你所看到的,有很多结果,但并不完全是我所期望看到的。在这两个例子中,我都得到了重复的数据


我做错什么了吗?我认为第一个示例应该已经打印了数组的全部内容。

您应该首先将所有结果提取到数组中,然后再打印它

UPD:要消除重复数据,请使用mysql\u fetch\u assoc而不是mysql\u fetch\u数组


UPD2:考虑使用MySQL扩展而不是MySQL。 你是说我们查询错了还是显示器坏了?我不清楚是什么问题解决了第一个问题。关于消除重复数据有什么想法吗?谢谢,这就解决了主要问题。关于如何消除重复数据数组[0]=>6703[属性id]=>6703[1]=>103[基本产品]=>103[2]=>1[数量基本产品]=>1[3]=>4[基本产品在手]=>4[4]=>4[可供客户使用]=>4@Coathanger将mysql获取阵列替换为mysql获取assoc

$result2 = mysql_query("SELECT 
ps_product_attribute.id_product_attribute AS attribute_id, 
ps_advanced_attributes.pack_product_id AS base_product, 
ps_advanced_attributes.pack_product_qty AS qty_base_product, 
ps_stock_available.quantity AS base_product_on_hand, 
FLOOR(ps_stock_available.quantity / ps_advanced_attributes.pack_product_qty) AS available_to_customer 
FROM ps_product_attribute 
JOIN ps_advanced_attributes ON ps_advanced_attributes.attribute_id = ps_product_attribute.id_product_attribute 
JOIN ps_stock_available ON ps_stock_available.id_product = ps_advanced_attributes.pack_product_id 
ORDER BY ps_product_attribute.id_product_attribute ASC, ps_stock_available.quantity DESC");

echo '<pre>';   
WHILE($db_field2 = mysql_fetch_array($result2)){
print_r($db_field2);}
echo  '</pre>';
Array

(

    [0] => 6703
    [attribute_id] => 6703
    [1] => 382
    [base_product] => 382
    [2] => 1
    [qty_base_product] => 1
    [3] => 69
    [base_product_on_hand] => 69
    [4] => 69
    [available_to_customer] => 69
)

Array

(

    [0] => 6703
    [attribute_id] => 6703
    [1] => 103
    [base_product] => 103
    [2] => 1
    [qty_base_product] => 1
    [3] => 4
    [base_product_on_hand] => 4
    [4] => 4
    [available_to_customer] => 4
)
Array
(

    [0] => 6703
    [attribute_id] => 6703
    [1] => 471
    [base_product] => 471
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
Array
(

    [0] => 6704
    [attribute_id] => 6704
    [1] => 103
    [base_product] => 103
    [2] => 1
    [qty_base_product] => 1
    [3] => 4
    [base_product_on_hand] => 4
    [4] => 4
    [available_to_customer] => 4
)
Array
(

    [0] => 6704
    [attribute_id] => 6704
    [1] => 397
    [base_product] => 397
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
Array
(

    [0] => 6704
    [attribute_id] => 6704
    [1] => 465
    [base_product] => 465
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
Array
(

    [0] => 6705
    [attribute_id] => 6705
    [1] => 103
    [base_product] => 103
    [2] => 1
    [qty_base_product] => 1
    [3] => 4
    [base_product_on_hand] => 4
    [4] => 4
    [available_to_customer] => 4
)
Array
(

    [0] => 6705
    [attribute_id] => 6705
    [1] => 533
    [base_product] => 533
    [2] => 1
    [qty_base_product] => 1
    [3] => 2
    [base_product_on_hand] => 2
    [4] => 2
    [available_to_customer] => 2
)
Array
(

    [0] => 6705
    [attribute_id] => 6705
    [1] => 469
    [base_product] => 469
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
Array
(

    [0] => 6706
    [attribute_id] => 6706
    [1] => 395
    [base_product] => 395
    [2] => 1
    [qty_base_product] => 1
    [3] => 41
    [base_product_on_hand] => 41
    [4] => 41
    [available_to_customer] => 41
)
Array
(

    [0] => 6706
    [attribute_id] => 6706
    [1] => 103
    [base_product] => 103
    [2] => 1
    [qty_base_product] => 1
    [3] => 4
    [base_product_on_hand] => 4
    [4] => 4
    [available_to_customer] => 4
)

Array
(

    [0] => 6706
    [attribute_id] => 6706
    [1] => 468
    [base_product] => 468
    [2] => 1
    [qty_base_product] => 1
    [3] => 0
    [base_product_on_hand] => 0
    [4] => 0
    [available_to_customer] => 0
)
$result = [];
while ($row = mysql_fetch_assoc($result2)){
    $result[] = $row;
} 
print_r($result);