suttercain Posted October 23, 2007 Share Posted October 23, 2007 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 https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/ Share on other sites More sharing options...
only one Posted October 23, 2007 Share Posted October 23, 2007 $2weeks = time() - 1209600; mysql_query("DELETE FROM `table` WHERE `date set` < '$2weeks'"); Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376361 Share on other sites More sharing options...
suttercain Posted October 23, 2007 Author Share Posted October 23, 2007 Thanks, I'll give that a go. SC Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376362 Share on other sites More sharing options...
GingerRobot Posted October 23, 2007 Share Posted October 23, 2007 Variable names cannot start with a number. Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376363 Share on other sites More sharing options...
only one Posted October 23, 2007 Share Posted October 23, 2007 Variable names cannot start with a number. Duh, I was only giving an example. Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376364 Share on other sites More sharing options...
suttercain Posted October 23, 2007 Author Share Posted October 23, 2007 What about an underscore? Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376378 Share on other sites More sharing options...
otuatail Posted October 23, 2007 Share Posted October 23, 2007 How is this date stored. Is it as time() Preferable. Desmond. Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376381 Share on other sites More sharing options...
suttercain Posted October 23, 2007 Author Share Posted October 23, 2007 mysql timestamp 9999-12-31 23:59:59 Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376385 Share on other sites More sharing options...
otuatail Posted October 23, 2007 Share Posted October 23, 2007 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 https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376391 Share on other sites More sharing options...
pocobueno1388 Posted October 23, 2007 Share Posted October 23, 2007 I'm not sure if this will work, but you can try it DELETE FROM table WHERE `date` > (NOW() - INTERVAL 14 DAYS) Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376399 Share on other sites More sharing options...
otuatail Posted October 23, 2007 Share Posted October 23, 2007 OR Delete from EventLog2 WHERE Date < '2007-03-01'; Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376403 Share on other sites More sharing options...
suttercain Posted October 23, 2007 Author Share Posted October 23, 2007 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 Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376409 Share on other sites More sharing options...
otuatail Posted October 23, 2007 Share Posted October 23, 2007 SELECT * FROM Table GROUP BY field order by ID Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376416 Share on other sites More sharing options...
atlanta Posted October 23, 2007 Share Posted October 23, 2007 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 https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376428 Share on other sites More sharing options...
suttercain Posted October 23, 2007 Author Share Posted October 23, 2007 No I just want the one that occurs the most. Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376458 Share on other sites More sharing options...
rajivgonsalves Posted October 24, 2007 Share Posted October 24, 2007 for the above you can try this out select count(*), fieldname from table group by fieldname having count(*)=max(count(*)); Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376856 Share on other sites More sharing options...
otuatail Posted October 24, 2007 Share Posted October 24, 2007 SELECT * FROM Table GROUP BY field_name order by field_name This will show all the totals starting with the highest Desmond. Link to comment https://forums.phpfreaks.com/topic/74480-how-to-delete-from-table-where-greater-than-2-week/#findComment-376920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.