开发者

PHP array grouping by ID

I have an a bunch of rows in an array with Order Numbers and other order data:

    Array ( [ORDER] => 257 [DATE] => 2011-06-13 [ITEM] => LOT98 [QTYORDERED] => 10.00 ) 
    Array ( [ORDER] => 258 [D开发者_JAVA技巧ATE] => 2011-06-15 [ITEM] => FF25 [QTYORDERED] => 450.00 ) 
    Array ( [ORDER] => 258 [DATE] => 2011-07-06 [ITEM] => FF25 [QTYORDERED] => 225.00 ) 
    Array ( [ORDER] => 259 [DATE] => 2011-06-08 [ITEM] => A151412 [QTYORDERED] => 90.00) 
    Array ( [ORDER] => 259 [DATE] => 2011-06-15 [ITEM] => A151412 [QTYORDERED] => 402.00 ) 
    Array ( [ORDER] => 259 [DATE] => 2011-07-06 [ITEM] => A151412 [QTYORDERED] => 357.00 ) 

I would like to place those rows into a single array grouped by ORDER No in a style similar to this:

    Order ID Date Item QTYOrdered
    257   0  xx   xx   xx
    258   0  xx   xx   xx
          1  xx   xx   xx
    259   0  xx   xx   xx
          1  xx   xx   xx
          2  xx   xx   xx

My code so far:

    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
    $RecordSet = $db->Execute("$q2");   
    while ($row = $RecordSet->FetchRow()) {}


In you while-loop:

$ordered[$row['ORDER']][] = $row;

after the loop you have that:

var_dump($ordered);

Automatically packed together based on the order-key.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜