Group Query Results in PHP

后端 未结 2 1268
独厮守ぢ
独厮守ぢ 2021-01-23 10:20

I am using the following query to populate a table:

$result = mysql_query(\"SELECT vendor, part_number, machine, Sum(q_received) AS received, Sum(q_rejected) AS          


        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 10:52

    You need to split your loop into two parts. First part checks if you've got a new/different vendor, and sets up the "outer" setup. Then the inner part which dumps out that vendor's parts.

    e.g.

    $prev_vendor = null;
    while($row = ...) {
        if ($row['vendor'] != $prev_vendor) {
           ... new vendor stuff ...
           $prev_vendor = $row['vendor']; // update vendor for next iteration
        }
        ... dump this row's machine data ...
    }
    

提交回复
热议问题