我有一个 MySQL 查询,它将几个表连接在一起以收集数据以供显示。我的目标是通过名为“project_id”的列显示数据。例子:
[project_id][project_name][order_date][ordered_by]
[31][project_a][2013-04-15][1]
[31][project_a][2013-04-16][1]
[31][project_a][2013-04-21][1]
[41][project_c][2013-02-21][1]
[41][project_c][2013-02-27][1]
所以我的问题是我不确定如何遍历数据数组以显示 project_id 一次,然后显示下面的数据,因为我将使用 jQuery 来切换/显示 project_id 的组数据
这是我的mysql查询:
SELECT p.user_customer_id,
p.name AS 'project_name',
p.project_id,
o.order_id,
o.order_date,
o.order_tech,
pro.name,
pro.purchase_price,
pro.sell_price
FROM project AS p
JOIN `order` AS o ON p.project_id = o.project_id
JOIN products_in_orders AS pir ON o.order_id = pir.order_id
JOIN product AS pro ON pir.product_id = pro.product_id
WHERE p.user_customer_id = 51
ORDER BY p.project_id ASC