好的,我想要做的是使用仅具有此特定ID的一个条件/特定行/行的开始日期和结束日期。
例如,如果仅 order_status ='1',则使用开始日期和结束日期,如果 order_status ='2',则选择ALL。我正在使用PHP从我的数据库中获取此信息,然后将它们存储在一个数组中。
目前,我有两个不同的查询可以为我完成此操作,但我必须将它们存储在两个不同的数组中,并将它们显示为两个不同的数组。我想要的是一种方法将所有这些存储到一个数组中,然后使用foreach循环在一个地方回显两个条件的所有结果。
希望它足够清楚,但如果没有,请通过评论告诉我,我也会包含我的代码和查询。
查询导出日期(order_status = 1)
SELECT ov.order_number,
m.name AS brand,
op.name AS model,
op.product_grade AS grade,
o.date_added
FROM `order` o,
op.order_product_veri,
manufacturer m,
product p
WHERE opv.product_id = p.product_id
AND p.manufacturer_id = m.manufacturer_id
AND op.order_status = '1'
AND Date (o.date_added) >= '2013-10-22'
AND Date(o.date_added) <= '2013-11-02'
查询导出而不日期(order_status = 2)
SELECT op.order_number,
m.name AS brand,
op.name AS model,
op.product_grade AS grade,
o.date_added
FROM `order` o,
op.order_product_veri,
manufacturer m,
product p
WHERE opv.product_id = p.product_id
AND p.manufacturer_id = m.manufacturer_id
AND op.order_status = '2'
答案 0 :(得分:0)
SELECT
op.order_number,
m.name AS brand,
op.name AS model,
op.product_grade AS grade,
o.date_added
FROM
order o,
op.order_product_veri,
manufacturer m,
product p
WHERE
opv.product_id = p.product_id and
p.manufacturer_id = m.manufacturer_id and
(
op.order_status = '2' or
(op_order_status = '1' and date(o.date_added) >= '2013-10-22' and date(o.date_added) <= '2013-11-02'
)