Click to See Complete Forum and Search --> : PHP and MySQL, Please Please help!!


hblueair
01-17-2006, 12:09 AM
HI everyone,

Does anyone know the PHP or Mysql script to control the timing of displaying information from the database? :confused: coz I want to set a timing for the news section which can auto delete the old news a month after the posting date .

Please kindly give advise!! Thanks a lot !! :)

Hebee

web_dude
01-17-2006, 03:31 AM
I'm not sure I understand your question,
but in one of my projects I wanted to show only the records that were created in the last hour.
I added a timestamp field to the records and when running the SELECT I limited the timestamp to be greater than current time - 1 hour.
I hope it helps.

Brooksie155
01-17-2006, 03:44 AM
If you are talking about physically removing the articles from the DB then you could set up a script to run on the crontab.

Using a timestamp field again the sql would be something like

// Build time stamp for cut off date (today - 1 month)
$ts = mktime(0,0,0,date('m') -1, date('d'), date('Y'));

// Query to delete record on or before cut off date, n.b. "Y-m-d" will return the
// date in american format - you may need to change that as required.
$sql .= "DELETE FROM tb_news WHERE timestamp <= '" . date("Y-m-d", $ts) . "'";

p.s. I think SQL has DATE() and NOW() functions so this can probably be scripted purely in SQL if desired.

Markbad311
01-17-2006, 07:30 AM
I use a INTERVAL in my query like this. what it does is display information for one week from the date I Set it to display.


$sql = "SELECT * FROM $table_name WHERE `date` BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";



See how it works you can do the same with your news and still keep the old news article safe in the DB for retrieving later!!

hblueair
01-17-2006, 09:12 PM
Thank you so much for all of you !! :D