View Full Version : Automatically delete advertisements with today's date

08-04-2008, 02:09 PM
I would need to automatically delete advertisements with today's date.

In the field '$till' there are the dates (DD-MON-YYYY) which have to be compared to the today's date.

$today = time(DD-MON-YYYY);
$rime = mysql_query("SELECT * FROM classified WHERE '$till'>'$today' ORDER BY add_date DESC LIMIT 3") or die(mysql_error());
while($row = mysql_fetch_array($rime))...

But the query is ignored as you can see clicking on the link. The second date in the advertisements is the expiry date '$till' http://www.veximchemicals.com/sunnyisland/index.php

What can I do? Thanks in advance.

08-04-2008, 03:27 PM
Didn't look that hard at your query, but comparing two constants isn't going to do anything for you... one of your operators needs to be a column in the table.

08-04-2008, 03:35 PM
$till is the operator in the column. (it's the field to be compared with $today.

When I had $expiry instead of $till it was everything ok.
The difference between them is that $expiry is generated by time(), it's numeric.
$till is DD-MON-YYYY.

As you can see in the code, I changed $today=time(); with $today=time(DD-MON-YYYY);
but it still doesn't work.

08-05-2008, 01:28 AM
$till is the operator in the column. (it's the field to be compared with $today.
Really? You named your table column "$till"? If that's the case.. with the dollar sign, escape it in your query, and use backticks instead of single quotes around it so you can make sure MySQL will treat it as a column and not a string.

Len Whistler
08-05-2008, 01:58 AM
How about

$today = time(DD-MON-YYYY);
mysql_query("DELETE FROM classified WHERE till = '$today' LIMIT 3");


08-05-2008, 09:11 AM
Really? You named your table column "$till"?

My column is named 'till'. And it is dd-mm-yyyy.
$today instead, is a numeric date, like 12932393291
I would need to change the current time, $today, from numeric to dd-mm-yyyy.
How can I do it?

$rime = mysql_query("SELECT * FROM classified WHERE till>$todayformat ORDER BY add_date DESC LIMIT 3") or die(mysql_error());

08-05-2008, 11:22 AM
$today = time();
$todaya = date('d-m-Y');
$rime = mysql_query("SELECT * FROM classified WHERE till>'$todaya' ORDER BY link_id DESC LIMIT 3") or die(mysql_error());
while($row = mysql_fetch_array($rime)) {....

This is the resolution, almost:
The order would have to be by day, month, year.
Instead it is by month, day, year. (till is also formatted as d-m-Y).

You can see the evolution of the problem here (http://www.veximchemicals.com/sunnyisland/index.php?cat=78)

08-05-2008, 05:11 PM
I have the perfect solution for you:

Make your "till" column a DATE data type.

It's impossible to do comparisons or sorts on a date in the format of dd-mm-yyyy. But MySQL takes care of it for you, you simply have to use the DATE data type.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum