私はもともとこのOther Questionを投稿していて、私の質問を拡大して、この質問に移っています。PHP配列内のユニークな値を並べ替える
MYSQL SELECT QUERY
からPHP
を使用して配列を分割し、一部の部分的な値を削除しようとしています。ここで
Array ([Order_ID] => 1 [Customer_ID] => 42534 [OrderDate] => [lotCode] => 401042 [qty] => 8 [0] =>
Array ([0] => 1 [Order_ID] => 1 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => 993647 [lotCode] => 993647 [4] => 9 [qty] => 9) [1] =>
Array ([0] => 1 [Order_ID] => 1 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => 401040 [lotCode] => 401040 [4] => 55 [qty] => 55) [2] =>
Array ([0] => 1 [Order_ID] => 1 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => 401040 [lotCode] => 401040 [4] => 66 [qty] => 66) [3] =>
Array ([0] => 1 [Order_ID] => 1 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => 401042 [lotCode] => 401042 [4] => 8 [qty] => 8))
Array ([Order_ID] => 7 [Customer_ID] => 42534 [OrderDate] => [0] =>
Array ([0] => 2 [Order_ID] => 2 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => [lotCode] => [4] => [qty] =>) [1] =>
Array ([0] => 3 [Order_ID] => 3 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => [lotCode] => [4] => [qty] =>) [2] =>
Array ([0] => 4 [Order_ID] => 4 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => [lotCode] => [4] => [qty] =>) [3] =>
Array ([0] => 5 [Order_ID] => 5 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => [lotCode] => [4] => [qty] =>) [4] =>
Array ([0] => 6 [Order_ID] => 6 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => [lotCode] => [4] => [qty] =>) [5] =>
Array ([0] => 7 [Order_ID] => 7 [1] => 42534 [Customer_ID] => 42534 [2] => [OrderDate] => [3] => [lotCode] => [4] => [qty] =>))
...
<?php
$withLotCodes = array();
$noLotCodes = array();
$OrdersToShip2 = mysql_query("
SELECT o.Order_ID, o.Customer_ID, o.OrderDate, olc.lotCode, olc.qty
FROM Orders o
LEFT JOIN OrdersLotCodes olc ON o.Order_ID = olc.Order_ID
WHERE o.LotCoded = 0 ORDER BY o.Order_ID");
if($OrdersToShip2) {
while ($info = mysql_fetch_array($OrdersToShip2))
{
if(!isset($info['lotCode'])){
// if NO lotCode
$noLotCodes['Order_ID'] = $info['Order_ID'];
$noLotCodes['Customer_ID'] = $info['Customer_ID'];
$noLotCodes['OrderDate'] = $info['OrderDate'];
array_push($noLotCodes,$info);
}else{
// if YES lotCode
$withLotCodes['Order_ID'] = $info['Order_ID'];
$withLotCodes['Customer_ID'] = $info['Customer_ID'];
$withLotCodes['OrderDate'] = $info['OrderDate'];
$withLotCodes['lotCode'] = $info['lotCode'];
$withLotCodes['qty'] = $info['qty'];
array_push($withLotCodes,$info);
}
}
}else{
echo "encountered an error.".mysql_error();
}
print_r($withLotCodes);
echo '<br><br>';
print_r($noLotCodes);
mysql_close($conn);
?>
ご覧のとおり、それは'lotCodes'
を持ち、受注にアップarray
を壊す...私は取得しています入れてます注文しないので、私は今2つのarrays
を持っています。
今、私が最初にarray
で'lotCode'
値を持つ'Order_ID'
'Customer_ID
& 'OrderDate'
について重複する値を削除しようとしています。私は一度だけ表示され、その後にlotCode値が多く表示されるようにしたい。
私はarray_unique
を使ってみましたが、残りの部分は出力に必要なlotCodes
で削除しました。
だから、何私はつもりはのようになります。
Order_ID, Customer_ID, OrderDate, lotCode, qty, lotCode, qty, lotCode, qty, lotCode, qty
の代わりに:
Order_ID, Customer_ID, OrderDate, lotCode, qty
Order_ID, Customer_ID, OrderDate, lotCode, qty
Order_ID, Customer_ID, OrderDate, lotCode, qty
Order_ID, Customer_ID, OrderDate, lotCode, qty
私はそれは明らかだ願っています。
この男の提案はありますか?あなたの実際のコードの面では
'Order_ID'を何度も取得することなく、' Order_ID'の一部である 'lotCode'と' qty'のそれぞれの値を取得します。私はちょうどそれのための適切な声明を理解することができません。 – Monty
@Montyオクラホマ、私はそれを提供するために私のコードを微調整し、もう少し説明を追加しました。 – liquorvicar