简体   繁体   中英

php mysql finding rows older than a day from date feald

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.

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

Your mistake...

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

There must be only one query and wrong num_rows name...

$sql= "SELECT * FROM uploads WHERE timestamp < '$timestamp'";
$efound = mysql_query($sql);
$enum = mysql_num_rows($efound);

PS The old myslq functions support ends at PHP 5.4 . Its good for you to start using myslqi or PDO mysql !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM