0

我对标题感到抱歉,获得标题很复杂。但请尝试阅读我在下面的声明。

我想合并表中具有相同名称但具有不同信息的数据。表示例:

form_no | name     | status | date_added
1       | keyboard | OK     | 19-APR-2013 (today)
2       | keyboard | NG     | 18-APR-2013 (yesterday)

现在我想在我的页面中显示它,只有 1 个信息合并为:
表格视图示例:

No | Item Name | Yesterday Status | Today Status
1  | keyboard  | NG               | OK

只是它,我想在表格视图中显示它,只需 1 个信息合并。它具有相同的名称,但根据添加的日期具有不同的状态。

<table>
<td>Item Name</td><td>Yesterday Status</td><td>Today Status</td>
</table>

include ("includes/_db_.php");

$today = date("j-F-Y");
$yesterday = date("j-F-Y", time() - 60 * 60 * 24);

$query = "SELECT * from t_production_status";
$result = mysql_query($query);

while ($data = mysql_fetch_array($result))
{
    $item_name = $data['name'];
    $status = $data['status'];
    $date_added = $data['date_added'];

<tr>
<td><?php echo $item_name; ?></td>
<td><?php echo $status; ?></td> <- this what I want show for yesterday status
<td><?php echo $status; ?></td> <- this what I want show for today status
<td><?php echo $date_added; ?></td>

有什么建议么 ?

4

1 回答 1

0

你有没有试过在你的状态表上做一个自我加入..

SELECT status1, status2 FROM t_production_status status1 JOIN t_production_status status1
WHERE status1.name = status2.name
AND status1.date = (today)
AND status2.data = (yesterday)

(未经测试,但应该是类似的东西)

http://dev.mysql.com/doc/refman/5.0/en/join.html

于 2013-04-26T08:20:59.000 回答