嗨,我的数据库中有这个。
id | status1 | status2 | time1 | time2 | time3 | time4 | time5 | userid | itemuid
1 | 2 | 1 | 000001| 000003| 000008 | 0 | 000099 | 15 | 620
2 | 2 | 1 | 000002| 000004| 000001 | 0 | 000002 | 620 | 15
现在我需要回应一些通知,问题是时间是在同一行..所以这是一个很大的问题,以便得到这个,例如我的条件看起来像
if ($actualuser == $userid && $status1==2)
echo notification
echo time4
if ($actualuser == $userid && $status2==1)
echo notification
echo time2
这对于每个循环来说都是一个问题,唯一的问题是我需要从最新的(最新的)到最旧的回声,如下面的例子......在这个例子中,这个想法会一直设置或排序,因为它只是一次列..是这个posibble吗?
item id1 time(000099)
item id1 time(000008)
etc
item id1 time(000001)
item id1 time(0)
item id2 time(0)
我该怎么做?再见这两个条件的方式就是例如..我喜欢使用相同格式的4或6个条件,但也许我不能这样做..我该怎么做才能为此设置通知...
谢谢..我迷失了
答案 0 :(得分:1)
所以,正如我在评论中所说,你需要做的如下:
select t.*, t2.times from yourtable t, (
select id, time1 times from yourtable union
select id, time2 from yourtable union
select id, time3 from yourtable union
select id, time4 from yourtable union
select id, time5 from yourtable ) t2
where t.id = t2.id
order by t2.times desc