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'";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计