airmermaid Posted April 8, 2011 Report Share Posted April 8, 2011 Hi all, I have a question regarding statistics. With the help of Michael I was able to get Pax and Cargo shown seperately. The code was : $query="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='P'";$result=DB::get_results($query); echo $result[0]->totalpax; Now I am trying to make something different (as usual I can't ). In my very simple logic I get total Pax Scheduled flights with the code above, then I get total Pax Charter changing flighttype as "H". Now the confusing part (for me) comes; how do I sum both to get total pax carried? Total Pax Carried = Total Pax Scheduled + Total Pax Charter What I have done was (OK don't laugh...kidding.. you can laugh as loud as you can ) $queryP="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='P'";$resultP=DB::get_results($queryP); $queryH="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='H'"; $resultH=DB::get_results($queryH); $total=$resultH + $resultP; echo $total[0]->totalpax; Cheers, Arslan Quote Link to comment Share on other sites More sharing options...
Nuclear Posted April 8, 2011 Report Share Posted April 8, 2011 $queryP="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='P'"; $resultP=DB::get_results($queryP); $queryH="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='H'"; $resultH=DB::get_results($queryH); $total=$resultH[0]->totalpax + $resultP[0]->totalpax; echo $total I don't remember what you were doing with this, but if you're not using the results for anything but just to get the totals, you can eliminate one of the queries: $query="SELECT SUM(`load`) as totalpax FROM `phpvms_pireps` WHERE `flighttype`='P' OR `flighttype`='H'"; $result=DB::get_results($query); $total=$result[0]->totalpax; Quote Link to comment Share on other sites More sharing options...
airmermaid Posted April 8, 2011 Author Report Share Posted April 8, 2011 Hi Michael, This is the quick stats at the frontpage. As flighttype P and H are seperately inserted in the database but they are both referring to number of pax I simply wanted to show total pax number flown (both charter and scheduled). Quote Link to comment Share on other sites More sharing options...
airmermaid Posted April 8, 2011 Author Report Share Posted April 8, 2011 Works great! You rock 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.