user2252976
user2252976

Reputation: 3

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.

Upvotes: 0

Views: 206

Answers (2)

echo_Me
echo_Me

Reputation: 37233

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

Upvotes: 2

Svetoslav
Svetoslav

Reputation: 4676

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);

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

Upvotes: 1

Related Questions