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 Quote Link to comment 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'"); Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 23, 2007 Share Posted October 23, 2007 Variable names cannot start with a number. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
suttercain Posted October 23, 2007 Author Share Posted October 23, 2007 What about an underscore? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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) Quote Link to comment 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'; Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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(*)); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.