匹配日期时间不显示结果

时间:2013-10-17 05:28:02

标签: 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());
    }

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

1 个答案:

答案 0 :(得分:0)

您需要使用日期方法来将日期与数据库进行比较。因此,在您的where条件中使用日期(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"]."'");
相关问题