php - 匹配日期时间不显示结果

标签 php mysql fetch

$link = new PDO("mysql:host=localhost;dbname=fashion",'root','');
$stmt=$link->prepare("select * from stylestatement where id='".$_REQUEST["you"]."'");
    if ($stmt->execute(array($_GET['title']))) {
        $row=$stmt->fetch();
        $newstmt=$link->prepare("select * from images where `statementid`='".$_REQUEST["you"]."' and `added_on`='".$row["created_on"]."'");
        $newstmt->execute();
        echo($newstmt->rowCount());
    }

在上面的代码中,即使我在图像表中有相同的日期时间,我得到结果= 0,为什么?

最佳答案

您需要使用日期方法 将日期与数据库进行比较。所以在你的 where 条件中使用 date(added_on) 而不是匹配日期的 added_on

替换

$newstmt=$link->prepare("select * from images where `statementid`='".$_REQUEST["you"]."' and `added_on`='".$row["created_on"]."'");  

$newstmt=$link->prepare("select * from images where `statementid`='".$_REQUEST["you"]."' and date(`added_on`)='".$row["created_on"]."'");

关于php - 匹配日期时间不显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19418898/

相关文章:

php - 以数组形式检索 mysql 数据并显示在多个组合框中

php - 表单元素与适配器中的 Zend_File_Transfer setDestination

php - 使用 mysql_real_escape_string 时更多的斜线

javascript - 在提取后调用后重定向

javascript - 刷新时未定义 Location 属性 (ReactJS)

php - 站点优化 - 添加图像尺寸

php - 使用 Propel ORM 将多个条目插入 Mysql 数据库

mysql - 存储具有不同属性的类似产品

mysql - 在带有日期的 Sequelize 中使用 Op.between 时出现 TypeScript 错误

javascript - 401(未经授权)在 Chrome 中,但在 IE 中没有