【问题标题】:How to go to next record by date when you pull records by ID?按ID拉记录时如何按日期转到下一条记录?
【发布时间】:2016-02-10 19:53:47
【问题描述】:

我有一个包含三个字段的表。事件 ID、名称、日期。我的网站按事件 ID 提取记录,但我希望下一个按钮按日期转到下一个记录。如何实现?例如:

1 testing 11.1.2015
2 testing 11.3.2015
3 testing 11.2.2015

指向页面的链接会拉入事件 ID,例如 www.testing.php?eventid=1

但是当我转到下一个时,我希望它按日期顺序而不是 ID 顺序。所以它应该转到事件 id 3。目前我的代码设置如下,我该如何调整它以使用日期字段?

$result5 = mysql_query("SELECT event_id FROM events group by event_id order by event_id DESC LIMIT 1") or die(mysql_error()); 
            while ($row5 = mysql_fetch_array($result5))
        {
        $maxevent= $row5['event_id'];

    <script>
$(document).on("pageinit",function(){

  var pathname = $(location).attr('href');
  var leva = $('#next').attr("href");
  var prava = $('#prev').attr("href");
  var preva = $('#ret').attr("href");

  $("body").on("swiperight",function(){
    <!--alert("You swiped right!");-->
    location.href=prava;
  }); 
    $("body").on("swipeleft",function(){
    <!--alert("You swiped left!");-->
    location.href=leva;
  });
if(leva === undefined) { 
 window.location.href="eventviewmusack.php?eventid=<?php echo $maxevent;?>";
}  


});
</script>

【问题讨论】:

  • 你为什么要在没有聚合函数的情况下进行分组?因为你喜欢它把它当作一个独特的东西来对待?
  • 大概您正在检索当前记录的日期?因此,您可以在下一个查询中使用它。只需执行WHERE eventdate &gt; thedateforthecurrentevent ORDER BY eventdate ASC LIMIT 1(伪代码,根据需要替换)
  • 如果 ID 的第一个事件是日期的最后一个事件怎么办?
  • 那么空结果是合适的
  • 通过date而不是`id`订购会给你你想要的。

标签: php mysql sorting date


【解决方案1】:

只需更改查询 User ORDER BY Date ASC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-31
    • 2020-08-22
    • 1970-01-01
    • 2018-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-16
    相关资源
    最近更新 更多