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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.