Guest Stormchaser Posted January 27, 2011 Report Posted January 27, 2011 My pilots love the landing rate module and have had a few requests to do it by month instead for all time. I have pilot stats module and landing rates combined on one page. Wondering if there is a way to combine top pilot module and landing rate module into one so landing rate pulls by month. Not much of a coder before I started this but learning how to copy and paste pretty good to manipulate code. Just asking if someone has done this already save me a great deal of time. And by the way always like to say thanks for phpvms! Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 Do you wan't limit the view to current month, or any mount? Quote
Moderators mark1million Posted February 3, 2011 Moderators Report Posted February 3, 2011 Current month with maybe a selection drop down? Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 For now, gives you current month. Assuming you are using the Touchdown stats from David Clark... Add the following to the file TouchdownStatsData.class.php located under common (BACKUP FIRST!!!!) MARK! Both inpastes must go over the last '}' brackets in the bottom of files. //Added by [your name] 2011.xx.xx get_stats_by_cur_month () $query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, landingrate, submitdate FROM `".TABLE_PREFIX."pireps` WHERE landingrate < '0' and MONTH(submitdate)=MONTH(curdate()) ORDER BY landingrate DESC"; return DB::get_results($query);} Then add to the following file under module, TouchdownStats TouchdownStats.php //Added by [your name] 2011.xx.xx public function top_landing_this_month () { $this->set('stats', TouchdownStatsData::get_stats_by_cur_month()); $this->show('touchdownstats/touchdownstats_index.tpl'); } Link to http://your.site.ok/TouchdownStats/top_landing_this_month The month selection require a bit more work. If you want limit the returned data, use same technique as above and paste in addition in TouchdownStatsData.class.php: //Added by [your name] 2011.xx.xx public function get_stats_by_cur_month_limited ($howmany) { $query = "SELECT pilotid, code, flightnum, depicao, arricao, aircraft, landingrate, submitdate FROM `".TABLE_PREFIX."pireps` WHERE landingrate < '0' and MONTH(submitdate)=MONTH(curdate()) ORDER BY landingrate DESC"; return DB::get_results($query); } And in th file TouchdownStats.php: public function top_landing_this_month_limited () { $this->set('stats', TouchdownStatsData::get_stats_by_cur_month_limited($howmany)); $this->show('touchdownstats/touchdownstats_index.tpl'); } To link limits use /top_landing_this_month_limited/X where x is the number you want to limit it to. Must say my database is rather slim, so I don't know how this will look in a big DB. Anyway copy the files you are manipulating, ALWAYS. Sorry for the brief answer, will come up with the month selection later. Make a mark that the scritp will return an error if the dataset is empty in the foreach clause in the tpl file. So probably you will get an error in the begining of each month . Regards 1 Quote
Moderators mark1million Posted February 3, 2011 Moderators Report Posted February 3, 2011 Cheers i will give that a go in a bit let you know, as for the error a simple, error_reporting(0); will stop that outputting to screen Quote
Moderators mark1million Posted February 3, 2011 Moderators Report Posted February 3, 2011 Right i have had to do a bit of syntax adjustment but its working to a point, the top function seems to pull back all the landings from every month, doesnt seem to limit by current month. I will keep playing and see what i can do Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 Ok, thats strange the and MONTH(submitdate)=MONTH(curdate()) in the SQL should limit that. Try replace curdate() with now(). Are you using mysql? Are you linking correctly? 1 Quote
Moderators mark1million Posted February 3, 2011 Moderators Report Posted February 3, 2011 OK the now() works but its bringing back all the years so Feb 2010 and 2011, how do i limit the year. Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 Ah, check if it takes data from other years? Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 Probably 100 ways tu fix, but add and year(submitdate) = year(curdate()) after the month(now()) clause 1 Quote
Moderators mark1million Posted February 3, 2011 Moderators Report Posted February 3, 2011 :) :) Top man. Thankyou. Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 Since my database is quite sparse, I am not sure, but I think the following sql will give you best landing grouped by month and pilot for a given year. You can test if you have webmin, phpmyadmin or heidi SQl Whatevere. Perhaps that is interestning? SELECT pilotid, date_format(submitdate,'%M') as month, code, flightnum, depicao, arricao, aircraft, max(landingrate) as 'best landing', format(avg(landingrate),2) as 'average', submitdate FROM `pireps` group by month(submitdate),(pilotid) having year(submitdate)=2011 Change year to whatever you like... Quote
Moderators mark1million Posted February 3, 2011 Moderators Report Posted February 3, 2011 Right i have this working and limiting nicely now I want to put this page in another page but i cant seem to get it to work, any ideas would be great, i have tried, <?php MainController::Run('TouchdownStats', 'display_TouchdownStats/top_landing_this_month'); ?> here is the page, http://www.easyjetva.com/index.php/TouchdownStats/top_landing_this_month cheers. Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 Right i have this working and limiting nicely now I want to put this page in another page but i cant seem to get it to work, any ideas would be great, i have tried, <?php MainController::Run('TouchdownStats', 'display_TouchdownStats/top_landing_this_month'); ?> here is the page, http://www.easyjetva.com/index.php/TouchdownStats/top_landing_this_month cheers. Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 Whatis wrong, any error messages? Quote
Moderators mark1million Posted February 3, 2011 Moderators Report Posted February 3, 2011 Sorry didn't explain fully, i want that data on another page but i cant include it as it needs to be ran as a url, Quote
Wingthor Posted February 3, 2011 Report Posted February 3, 2011 Sorry didn't explain fully, i want that data on another page but i cant include it as it needs to be ran as a url, Yes, you have to change to URL. Assumingen the files has been copied in the directories as described, you just add /index.php/TouchdownStats/top_landing_this_month to you site's URL. When I click on the URL you sent the page comes up fine? Regards Quote
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.