1

在我的页面中,我有一个名为“最近的活动”的选项卡,我必须在其中显示两种不同类型的操作

  • 最近添加的选择
  • 最近投票的选择

je_addchoice 的表结构

je_addpoll 表

poll_id | user_id | poll_name | category_id | start_date | end_date

  1     |   20    |Naturalflrs|    18       | 2012-12-03 | 2095-12-25

je_addchoice 表

choice_id | poll_id | choice_creator_id | choice_name | choice_image | description | ctime

     1    |    1    |        20         |  Greenish   | forest.jpg   | forest      |135453

je_user_vote 表

vote_id | user_id | poll_id | choice_id | datetime_voted | user_type

  12    |  31     |    1    |   1       |12-12-2606:23:17|  normal

我已经有结果页面显示如下

显示最近添加的选项

使用查询显示以上结果

$result=mysql_query("SELECT * FROM je_addchoice, je_addpoll where je_addpoll.start_date <= '$check_date' AND je_addpoll.end_date >='$check_date'  AND je_addpoll.poll_id=je_addchoice.poll_id order by je_addchoice.choicecreationtime desc");

两张表

1) je_addpoll(民意调查的主表)

2) je_addchoice(为投票添加选项)

但我在这里要做的是如果任何用户投票支持投票,它将存储到

je_user_vote 表如上所示。

我想在同一选项卡中显示最近投票的选项

4

1 回答 1

1

试试这个

使用之前desc的订单datetime_votedje_addchoice.choicecreationtime desc

像这样。

$result=mysql_query("SELECT * FROM (SELECT P.poll_id,P.user_id,P.poll_name,P.category_id,P.start_date,P.end_date,C.choice_id,C.choice_creator_id,C.choice_name,C.choice_image,C.description,C.ctime FROM je_addchoice C, je_addpoll P where P.start_date <= '$check_date' AND P.end_date >='$check_date'  AND P.poll_id=C.poll_id order by C.choicecreationtime desc) N,je_user_vote U WHERE U.poll_id=N.poll_id order by U.datetime_voted desc,N.choicecreationtime desc");

或者

$result=mysql_query("SELECT N.poll_id,N.user_id,N.poll_name,N.category_id,N.start_date,N.end_date,N.choice_id,N.choice_creator_id,N.choice_name,N.choice_image,N.description,N.ctime FROM (SELECT P.poll_id,P.user_id,P.poll_name,P.category_id,P.start_date,P.end_date,C.choice_id,C.choice_creator_id,C.choice_name,C.choice_image,C.description,C.ctime FROM je_addchoice C, je_addpoll P where P.start_date <= '$check_date' AND P.end_date >='$check_date'  AND P.poll_id=C.poll_id order by C.choicecreationtime desc) N,je_user_vote U WHERE U.poll_id=N.poll_id order by U.datetime_voted desc,N.choicecreationtime desc");
于 2012-12-26T05:45:44.330 回答