[Solved] ORDER_BY date LIMIT 1 [duplicate]


First of all, you should use prepared statements like this:

$note = "SELECT * 
    FROM notify 
    WHERE seeker=:seeker AND donor=:donor 
    ORDER BY `date` DESC
    LIMIT 1";

$st = $conn->prepare($note);
$st->execute(array(
    ':seeker' => $_SESSION['email'],
    ':donor' => $email,
);

Without the place holders you’re still open to SQL injection.

Second, you can’t compare a string with an integer in this way:

$now = $time; // string
$old_date = strtotime($found['date']); // integer
$dateif = $now - $old_date; // dunno?

You should compare apples with apples:

$seven_days_ago = strtotime('-7 days');
$old_date = strtotime($found['date']);

if ($old_date > $seven_days_ago) {
    echo "difference between tow dates is less than 7 days";
} else {
    echo "the difference between tow dates is 7 days or more";
}

7

solved ORDER_BY date LIMIT 1 [duplicate]