MySQL 查询中基本 mktime() 的问题

发布于 2024-12-09 01:56:46 字数 717 浏览 3 评论 0原文

我尝试使用基本查询来了解数据库查询中的时间戳。我有一个带有“时间”字段的数据库,它是时间戳。我有一个基本查询来返回“时间”大于键控值($t1)的记录。我已检查 mytime() 的格式是否正确(注释掉以说明)。我今天的日期有一个记录。当我更改 $t1 的值时,我期望它返回或不返回......但事实并非如此。我哪里出错了?

 date_default_timezone_set('欧洲/伦敦');
    $year = '2011';
    $month = '10';
    $day = '11';
    $t1 = mktime(0,0,0, $month, $day, $year);
    //echo date("d/m/y : H:i:s", $t1); // this works fine!


    mysql_select_db(DATABASE_NAME, $connection);
    $client = "demo/";

    $result = mysql_query
    (
        "SELECT *
        FROM " .SESSIONDB. " 
        WHERE client = '$client' 
        AND page = 'interaction.php'
        AND time > '$t1'
        "
    ); 

Im trying a basic query to learn about timestamps in db queries. I have a db with a field 'time' which is a timestamp. I have a basic query to return records where "time" is greater than a keyed value ($t1). I have checked that mytime() is formatted correctly (commented off to illustrate). I have a single record set to todays date. I'm expecting it to return or not as I change the value of $t1 ... but it's not. where am I going wrong?

  date_default_timezone_set('Europe/London');
    $year = '2011';
    $month = '10';
    $day = '11';
    $t1 = mktime(0,0,0, $month, $day, $year);
    //echo date("d/m/y : H:i:s", $t1); // this works fine!


    mysql_select_db(DATABASE_NAME, $connection);
    $client = "demo/";

    $result = mysql_query
    (
        "SELECT *
        FROM " .SESSIONDB. " 
        WHERE client = '$client' 
        AND page = 'interaction.php'
        AND time > '$t1'
        "
    ); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2024-12-16 01:56:46

您将记录设置为

mktime(0,0,0, $month, $day, $year);

并将变量设置为

$t1 = mktime(0,0,0, $month, $day, $year);

但您使用 > 比较两者(超过)... 2 不是 > 2、它是 == 或 >=

:)

You set the record to

mktime(0,0,0, $month, $day, $year);

and you set your variable to

$t1 = mktime(0,0,0, $month, $day, $year);

But you compare the two using > (more than)... 2 is not > 2, it is == or >=

:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文