Jump to content

[SOLVED] How to remove entries in a DB that are a week old?


techiefreak05

Recommended Posts

I ahve a social network and I have a bulletin system, taht allows users to post bulletins that all their friedns can read... well anway, i dont want the bulletin to just sit there and take up DB space, how would i go about removing "bulletins" that are over a week old?

i wrote this but it isnt working. no error, but its not echoing the ids.

 

<?php
$query_x="SELECT * FROM `bulletins` WHERE `date` < " . date('F d, g:i', (time()-(3600*24*7)));
$result_x=mysql_query($query_x);
while($array_x=mysql_fetch_assoc($result_x)){
$test_x=$array_x['id'];
echo $test_x . "<br>";
}
?>	

<?php
$query_x="SELECT * FROM `bulletins` WHERE `date` < " . date('F d, g:i', (time()-(3600*24*7)));
$result_x=mysql_query($query_x) or die(mysql_error());
while($array_x=mysql_fetch_assoc($result_x)){
$test_x=$array_x['id'];
echo $test_x . "<br>";
}
?>	

 

Try that if not try this:

 

<?php
$query_x="SELECT * FROM `bulletins` WHERE `date` < (NOW() + (3600*24*7))";
$result_x=mysql_query($query_x) or die(mysql_error());
while($array_x=mysql_fetch_assoc($result_x)){
$test_x=$array_x['id'];
echo $test_x . "<br>";
}
?>	

 

Now if that does not work, try doing > instead of <

 

Date operations confuse me sometimes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.