doudie2693 2013-04-06 21:02
浏览 89

php mysql从日期字段中查找超过一天的行

Here is how it should be:

  1. search the database for uploads older than a day.
  2. output the id's for the uploads in a list.

here is what I have so far:

<?php
include 'config.php';
$connect = mysql_connect(DB_HOST, DB_USER, DB_PASS);
mysql_select_db(DB_NAME);

$timestamp = strtotime("-1 days");
$efined = mysql_query("SELECT * FROM uploads WHERE timestamp < '$timestamp'");
$efound = mysql_query($efined);
$enum = mysql_numrows($efound);
$ecount = 0;
echo $enum.'records were found.';
while ($ecount < $enum) {
    $euid = mysql_result($efound,$ecount,"uid");
    echo $euid.'<br>';
    $ecount++;
}
mysql_close($connect);
?>

currently, this outputs nothing, when there is a record 3 days old. How would I spesify the date format? in my database, it looks like this: 2013-04-02. thanks for any help, josh.

  • 写回答

2条回答 默认 最新

  • doutiaosu2310 2013-04-06 21:09
    关注

    this

       $enum=mysql_numrows($efound);
    

    should be

      $enum=mysql_num_rows($efound);
    

    EDIT.

    try your sql like that

       where  timestamp < date('now', '-1 days')
    

    edit:

    you are defining two mysql_query

    change this

        $efined = mysql_query("SELECT * FROM uploads WHERE timestamp < '$timestamp'");
    

    to

       $efined = "SELECT * FROM uploads WHERE timestamp < '$timestamp'";
    
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路