Jump to content

How to: DELETE * FROM table WHERE Greater than 2 week


suttercain

Recommended Posts

Hi guys,

 

I am building a module that displays the headline from a page that had the most hits last week. I was able to figure this out in PHP. I would now like to know how to delete and records that are over 2 weeks old. Anyone know how to do this in the mysql query?

 

Thanks.

 

SC

Ok pitty If it was time() you would be dealing with numbers. Sugest sometime, you create an extra field and populate it with this. as in

$stamp = strtotime(original-date-format)

new-field = $stamp. This is very flexable format.

1209600 = 2 weeks in seconds.

 

will have to put something together for you.

 

Desmond.

 

Anyone know how to grab the most occurrences in a column? Let's say A appears 10 times in the column and B occurs 25 times.... anyway to pluck out B?

 

Thanks

 

 

You want to query the database for all occurences of A and B then compare them using php ex.

$query1 = "SELECT * FROM `table` WHERE `field` = A";

$query2 = "SELECT * FROM `table` WHERE `field` = B";

$num_rows1 = mysql_num_rows($query1);

$num_rows2 = mysql_num_rows($query2);

 

if ($num_rows1 > $num_rows2)

{

echo $num_rows1;

or

do something with $numrows1

}

else

{

echo $num_rows2;

or

do something with $numrows2

}

 

understand?

 

 

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.