1

我说数据库中有 12 个结果,其列名为

thread

message

time_posted

有 12 个结果,它们都有相同的thread女巫是 1002。

我正在努力获得所有结果time_posted "2013-03-19 17:36:08"。两边至少有 4 个条目,所以我应该在这段时间之后得到 4 个条目。

到目前为止,在我尝试过的所有内容中,我要么收到了一个空数组,要么得到了除了2013-03-19 17:36:08时间戳记的行之外的所有内容。

这是我尝试过的:

    public function get_messages($thread){

        $time = '2013-03-19 17:36:08';

        $statement = $this->database->prepare("SELECT * FROM chat WHERE thread = ? AND time_posted > '$time'");

        $statement->bindParam(1, $thread);

        $statement->execute();

        $this->result = $statement->fetchAll(PDO::FETCH_ASSOC);

        return $this->result;

    }

我用 < AND > 都试过了

提前感谢您的帮助。

一切顺利。

康纳

4

1 回答 1

1

尝试这个:

    $time = '2013-03-19 17:36:08';

    $statement = $this->database->prepare("SELECT * FROM chat WHERE thread = ? AND time_posted >= STR_TO_DATE(?, '%Y-%m-%d %H:%i:%s')");

    $statement->bindParam(1, $thread);
    $statement->bindParam(2, $time );

    $statement->execute();
于 2013-02-19T21:21:59.020 回答