Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按时间和日期筛选_Php_Mysql_Time_Timestamp - Fatal编程技术网

Php 按时间和日期筛选

Php 按时间和日期筛选,php,mysql,time,timestamp,Php,Mysql,Time,Timestamp,我试图从MySQL数据库中筛选结果,但运气不太好 用户将填写一份表格,其中包含一份自2013年11月1日至2013年11月14日的日期 以下是我过滤结果的代码: $dbserver = "localhost"; $dbname = "nameofDB"; $dbusername = "username"; $dbpassword = "password"; $mysqli = new mysqli($dbserver, $dbusername, $dbpassword, $dbname);

我试图从MySQL数据库中筛选结果,但运气不太好

用户将填写一份表格,其中包含一份自2013年11月1日至2013年11月14日的日期

以下是我过滤结果的代码:

$dbserver = "localhost";
$dbname = "nameofDB";
$dbusername = "username";
$dbpassword = "password";

$mysqli = new mysqli($dbserver, $dbusername, $dbpassword, $dbname);

$query = "SELECT * FROM transfer WHERE personID = 84587749 AND DATE(time) BETWEEN ? AND ?";

if($stmt = $mysqli->prepare($query)){

    /*
    Binds variables to prepared statement


    i    corresponding variable has type integer
    d    corresponding variable has type double
    s    corresponding variable has type string
    b    corresponding variable is a blob and will be sent in packets
    */

   $to = $_POST['to'];
   $from = $_POST['from'];

   $stmt->bind_param('ss', $from, $to);


   /* execute query */
   $stmt->execute();

   /* Get the result */
   $result = $stmt->get_result();

   while ($row = $result->fetch_assoc()) {
        // Configure this how you want to print out each row.
        echo 'Details: '.$row['details'].'<br>';
        echo 'Time: '.$row['time'].'<br>';
        echo 'Balance: '.$row['balance'].'<br>';
        echo '<br><br>';
   }

   /* free results */
   $stmt->free_result();

   /* close statement */
   $stmt->close();
}

/* close connection */
$mysqli->close();

这没有显示任何结果,有人能帮忙吗?

您从$\u POST获得了哪些价值观?除非它们与mysql标准日期/时间字符串完全对应,例如

 yyyy-mm-dd
如果没有适当的转换逻辑,就不能直接将这些$\u POSt值填充到查询中

e、 g

不是有效的比较,但

... WHERE DATE(TIME) BETWEEN '2013-01-31' and '2013-02-28' 

是有效的。

@user2149630:你为什么一遍又一遍地问同一个问题?您已经知道如何转换日期格式。还有@Glavić——因为似乎没有人知道如何从表单中实现这一点,这是不可能的吗?不管表单提交了什么。如果要将这些from-a-form-dates传递到mysql中,则必须遵守mysql的日期/时间字符串标准。
... WHERE DATE(TIME) BETWEEN '2013-01-31' and '2013-02-28'