koughman Posted February 7, 2006 Share Posted February 7, 2006 im looking for a mysql script to show the last 45 entries ordered by score in the past month, thanks Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/ Share on other sites More sharing options...
fenway Posted February 8, 2006 Share Posted February 8, 2006 Try the following (UNTESTED):[code]SELECT * FROM yourTable WHERE DATE_SUB(yourDate, INTERVAL 1 MONTH)<=NOW() ORDER BY score DESC LIMIT 45[/code]Make sure you have appropriate indexes. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11458 Share on other sites More sharing options...
wickning1 Posted February 8, 2006 Share Posted February 8, 2006 If you're storing individual votes then you need a GROUP BY:[code]SELECT entry, COUNT(*) as cnt FROM votetable WHERE voteDate >= NOW() - INTERVAL 1 MONTH GROUP BY entry ORDER BY cnt DESC LIMIT 45[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11471 Share on other sites More sharing options...
koughman Posted February 8, 2006 Author Share Posted February 8, 2006 in this query[code]SELECT * FROM yourTable WHERE DATE_SUB(yourDate, INTERVAL 1 MONTH)<=NOW() ORDER BY score DESC LIMIT 45[/code] what do you mean by yourdate? like the date of the entry, in that case im using php date function and wouldnt that screw it up? Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11480 Share on other sites More sharing options...
fenway Posted February 8, 2006 Share Posted February 8, 2006 If so, you can always use STRTODATE() to convert into from a "date-like" string to a proper SQL date. Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11482 Share on other sites More sharing options...
koughman Posted February 9, 2006 Author Share Posted February 9, 2006 so then [code]SELECT * FROM yourTable WHERE DATE_SUB(STRTODATE(), INTERVAL 1 MONTH)<=NOW() ORDER BY score DESC LIMIT 45[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11485 Share on other sites More sharing options...
Helljumper Posted February 9, 2006 Share Posted February 9, 2006 Nah, dude.`yourTable` is the name of the SQL table that this data is stored in.`yourDate` is the field of your table that the date is in. Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11486 Share on other sites More sharing options...
fenway Posted February 9, 2006 Share Posted February 9, 2006 You should check the syntax of the STR_TO_DATE() function -- you need to pass in your PHP date string, and then define how it is composed: for example, STR_TO_DATE('04/31/2004', '%m/%d/%Y'). Simply substitute your PHP date for the date string and you're done. Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11487 Share on other sites More sharing options...
koughman Posted February 10, 2006 Author Share Posted February 10, 2006 [!--quoteo(post=343993:date=Feb 8 2006, 11:32 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Feb 8 2006, 11:32 PM) [snapback]343993[/snapback][/div][div class=\'quotemain\'][!--quotec--]You should check the syntax of the STR_TO_DATE() function -- you need to pass in your PHP date string, and then define how it is composed: for example, STR_TO_DATE('04/31/2004', '%m/%d/%Y'). Simply substitute your PHP date for the date string and you're done.[/quote]my date is like January 5th 2005 and im a n00b with php/mysql can one of you plz help with the exact script, thanks Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11523 Share on other sites More sharing options...
fenway Posted February 10, 2006 Share Posted February 10, 2006 Yeah, the date suffix is going to be a problem -- if this is coming from PHP, you have your choice of how this is represented; pick something useful instead. Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11529 Share on other sites More sharing options...
koughman Posted February 10, 2006 Author Share Posted February 10, 2006 so without using mysql and using php is there a way i can get a script that shows the past 45 best entries? Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11564 Share on other sites More sharing options...
fenway Posted February 10, 2006 Share Posted February 10, 2006 No, without MySQL you can't do it at all. Quote Link to comment https://forums.phpfreaks.com/topic/3350-monthly-top-45-script/#findComment-11566 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.