I'm trying to delete the past 2 months in my database.
I'm saving things in my database like this format date("n-Y");
zo the output would be 8-2013
Now i'm trying to delete the past 2 months like this:
Code:
echo "<h2>Opruimen.</h2>";
$AFGELOPENMAAND = date("n-Y",strtotime("-1 Months"));
$AFGELOPENMAAND2 = date("n-Y",strtotime("-2 Months"));
$result = $pdo->prepare("SELECT * FROM photos WHERE geupload = $AFGELOPENMAAND OR geupload = $AFGELOPENMAAND2");
$result->execute();
$hoeveel = $result->rowCount();
if($hoeveel != 0){
foreach($result as $row){
unlink($row["thumb"]);
unlink($row["location"]);
$resultDEL = $pdo->prepare('DELETE FROM photos WHERE id = :id');
$resultDEL->execute(array(':id' => $row["id"]));
echo 'De vorige 2 maanden zijn verwijdert.';
echo '<meta http-equiv="refresh" content="2; URL=admin.php">';
}
}else{
echo 'Deze actie is al uitgevoerd of het is niet nodig!!';
}
But i can see with my else, if he found something or not. And it doesn't find rows in my database, but there are some with the past 2 months in it.
Am i doing something wrong with my query ?
Grz