doupeng3501 2017-05-23 07:37
浏览 20

在php中相同的时间戳下降条件

I have given some timestamp condition descending , but if all timestamp are equals then descending condition is not working . It's returning the first row only, I need the last row.

below is code

         $this->db->like("time_stamp",$_POST['date'],"after");
         $this->db->order_by("time_stamp DESC");
         $this->db->limit("1");
         $query5= $this->db->get_where("report",array("student_id" => $student_id));

Please check table screenshot.

enter image description here

I need the last row ,not the first . here timestamp is same , so its not coming .

is there any way to do it ??

  • 写回答

2条回答 默认 最新

  • dongsang6899 2017-05-23 07:45
    关注

    You cannot do further sorting when the data is exactly the same. What you can do is set a 2nd criteria when data is the same, it'll continue to the second criteria for ordering.

    Normally you use your ID value. If you want the latest added you can use the below.

     $this->db->order_by("time_stamp DESC");
     $this->db->order_by("id DESC"); // this is the new line in your code
    

    If you want the earlier added you can use the below code.

    $this->db->order_by("time_stamp DESC");
    $this->db->order_by("id"); // by default is ASC
    

    Another way is like this in 1 row

    $this->db->order_by("time_stamp DESC, id DESC");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度