duanlvxi8652 2017-07-29 16:47
浏览 25

来自表的PHP数据,其中今天的日期在两个字段的范围内

I have a table called orders with orderID, StartDate, EndDate, etc.

I want to find if today's date falls within StartDate and EndDate. As a starting point I want to print the result that apply

This is my code I just cannot make it work. Also, CURDATE() does not work for me.

 <?php
    //$originalDate = "2010-03-21";
    //$newDate = date("d-m-Y", strtotime($originalDate));

 include "dbh.php";

   $today = DATE("Y-m-d");
    // WHERE $today > StartDate OR $today < EndDate OR $today > SuspendEnd 
 OR $today < SuspendStart";

   //{
     //  echo $today;
   //}


    $sql= "SELECT * FROM orders 
    WHERE $today = StartDate
    ";

    $records = mysqli_query($conn,$sql);

    while($row = mysqli_fetch_assoc($records)){

        echo "<tr>";

        echo "<td>".$row['OrderID']."</td>";
        //echo "<td>".$row['StartDate']."</td>";

        echo "</tr>";

    }

 ?>
  • 写回答

2条回答 默认 最新

  • doulan7166 2017-07-29 16:59
    关注

    I dont have mysql running to test this out but you can try

    select orderID from orders where (CURDATE() between StartDate and EndDate)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动