James142 Posted April 2, 2011 Report Share Posted April 2, 2011 Im trying to get the Percentage of something but its not working. This is what I have dont so far: <?php $flown = 20; $total = 100; $final_percentage = $total * ( 1 - $flown/100); echo "Final Percentage: ".$final_percentage; ?>% But it ends up with 80% when it should be 20% (20/100). Does anyone know where I went wrong? Thanks, James Quote Link to comment Share on other sites More sharing options...
Tom Posted April 2, 2011 Report Share Posted April 2, 2011 Your PHP is fine, your maths is not as good <?php $flown = 20; $total = 100; $final_percentage = ($flown/$total) * 100; echo "Final Percentage: ".$final_percentage; ?>% 1 Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 Your PHP is fine, your maths is not as good <?php $flown = 20; $total = 100; $final_percentage = ($flown/$total) * 100; echo "Final Percentage: ".$final_percentage; ?>% Brilliant thanks! +1 Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 I have ran into another problem. Does anyone know how I can get the total distance of the route a pilot is flying to show in the acars map? thanks Quote Link to comment Share on other sites More sharing options...
Nuclear Posted April 2, 2011 Report Share Posted April 2, 2011 By flight number: SchedulesData::findFlight($flightnum) By flight id: SchedulesData::getSchedule($flightid) Example: $flightinfo=SchedulesData::findFlight($flightno); $dist=$flightinfo->distance; Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 By flight number: SchedulesData::findFlight($flightnum) By flight id: SchedulesData::getSchedule($flightid) Example: $flightinfo=SchedulesData::findFlight($flightno); $dist=$flightinfo->distance; Sorry I'm abit confused here :S When I add </php $flightinfo=SchedulesData::findFlight($flightno); $dist=$flightinfo->distance; ?> to the acars.tpl file, nothing shows up? Thanks, James Quote Link to comment Share on other sites More sharing options...
Nuclear Posted April 2, 2011 Report Share Posted April 2, 2011 This was just an example. I don't know what your existing code is, so I can't tell you exactly what you need to do, but once you get $dist, you need to 'echo' the value where you want it. Using the above example: </php $flightinfo=SchedulesData::findFlight($flightno); $dist=$flightinfo->distance; echo 'Distance: '.$dist;?> 1 Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 (edited) This was just an example. I don't know what your existing code is, so I can't tell you exactly what you need to do, but once you get $dist, you need to 'echo' the value where you want it. Using the above example: </php $flightinfo=SchedulesData::findFlight($flightno); $dist=$flightinfo->distance; echo 'Distance: '.$dist;?> I currently only know the basics of php, When I put <?php $flightinfo=SchedulesData::findFlight($flightno); $dist=$flightinfo->distance; echo 'Distance: '.$dist;?> into the acarsmap.tpl file it doesnt show anything. Do I have to put something into acars.php for the distance to show up? Edited April 2, 2011 by James142 Quote Link to comment Share on other sites More sharing options...
Nuclear Posted April 2, 2011 Report Share Posted April 2, 2011 I didn't realize you were trying to alter the acarsmap.tpl. This is a lot more complicated. I'd have to look at it and I'm not sure whether I'd be able to figure it out Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 I didn't realize you were trying to alter the acarsmap.tpl. This is a lot more complicated. I'd have to look at it and I'm not sure whether I'd be able to figure it out I should have included what I was trying to do :S To make it clear here is what I am trying to do: On the ACARS map (live map) I'm putting in a JavaScript progress bar to show how much % of the flight a pilot has completed on his journey. But in order to calculate it I need the total distance of the actual flight. I am unable to get that code.. Thanks for all the support so far! James Quote Link to comment Share on other sites More sharing options...
Nuclear Posted April 2, 2011 Report Share Posted April 2, 2011 No problem. If I have time this weekend, I'll look at it, but I don't have much experience with JS (which the acars map uses). Quote Link to comment Share on other sites More sharing options...
Tom Posted April 2, 2011 Report Share Posted April 2, 2011 I don't think you're going to have much luck with this unless you can use the javascript variables already given in the comments (which wouldn't really allow you to do what you want). The way the ACARS map is done is unfortunately really... odd. Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 I don't think you're going to have much luck with this unless you can use the javascript variables already given in the comments (which wouldn't really allow you to do what you want). The way the ACARS map is done is unfortunately really... odd. Damn :/ I was really looking forward to see this work aah well Quote Link to comment Share on other sites More sharing options...
Nuclear Posted April 2, 2011 Report Share Posted April 2, 2011 I don't think you're going to have much luck with this unless you can use the javascript variables already given in the comments (which wouldn't really allow you to do what you want). The way the ACARS map is done is unfortunately really... odd. Yeah, I agree. I don't know if it's "odd", but it certainly isn't as straightforward as the other templates. The only way would be to edit the JS to expose the new variable. Quote Link to comment Share on other sites More sharing options...
Tom Posted April 2, 2011 Report Share Posted April 2, 2011 I had a quick look and it doesn't look like you'd even be able to get it by editing the javascript, you'd need to do a few more things in PHP. Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 I had a quick look and it doesn't look like you'd even be able to get it by editing the javascript, you'd need to do a few more things in PHP. I spent ages getting the bar working (http://www.flyaerova.com/table/index.html) looks like it was a waste of time now Thanks for the suggestions anyways! May I ask are you talking about the javascript in the live map or in the progress bar? Quote Link to comment Share on other sites More sharing options...
Tom Posted April 2, 2011 Report Share Posted April 2, 2011 Javascript in the acars map. I had assumed you were doing a static percentage bar In fact, scrap what I said earlier. Go look at core/modules/ACARS/ACARS.php - in the data function. within the foreach loop you can get the route distance and set it as a variable to return to the javascript. That should work Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 (edited) Javascript in the acars map. I had assumed you were doing a static percentage bar Nope it is a javascript as is changes colour as the % gets bigger. <- Again my fault for not giving all the information in the topic. I tested it with php and it worked so its just the acars :/ EDIT: I made it look like I was giving out to you, so I changed this reply Edited April 2, 2011 by James142 Quote Link to comment Share on other sites More sharing options...
Tom Posted April 2, 2011 Report Share Posted April 2, 2011 Erm no it is a javascript as is changes colour as the % gets bigger. I tested it with php and it worked so its just the acars :/ Yeah I didn't know that did I, I had never seen it, hence assumed it would be static. Anyway, read my edit Quote Link to comment Share on other sites More sharing options...
James142 Posted April 2, 2011 Author Report Share Posted April 2, 2011 In fact, scrap what I said earlier. Go look at core/modules/ACARS/ACARS.php - in the data function. within the foreach loop you can get the route distance and set it as a variable to return to the javascript. That should work I do hate having to keep asking for more help :S but would the foreach loop look something like this: $distance= OperationsData::GetRouteInfo($this->get->distance); if(!$distance) { $distance = OperationsData::RetrieveRouteInfo($this->get->distance); } Quote Link to comment Share on other sites More sharing options...
James142 Posted April 3, 2011 Author Report Share Posted April 3, 2011 Where is the route information stored and how would I recall it? Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted April 3, 2011 Moderators Report Share Posted April 3, 2011 Routes are in your schedules if thats what you mean? If you take a look in to the schedule_brief.tpl you can see the code there that calls it. Quote Link to comment Share on other sites More sharing options...
James142 Posted April 3, 2011 Author Report Share Posted April 3, 2011 Routes are in your schedules if thats what you mean? If you take a look in to the schedule_brief.tpl you can see the code there that calls it. Yes but i need the total distance of a flight the pilot is flying to be shown on the live flight map (Im making a progress bar and I need the total distance of the flight in order to get the % of the flight completed) If you get what i mean.. Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted April 3, 2011 Moderators Report Share Posted April 3, 2011 Ah ok great idea, let me have a look, ill get back to you. Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted April 3, 2011 Moderators Report Share Posted April 3, 2011 OK in that schedule briefing tpl the function in there, <?php echo "{$schedule->distance}"; ?> Quote Link to comment Share on other sites More sharing options...
James142 Posted April 3, 2011 Author Report Share Posted April 3, 2011 OK in that schedule briefing tpl the function in there, <?php echo "{$schedule->distance}"; ?> Still abit confused here, when I put <?php echo "{$schedule->distance}"; ?> into the acarsmap.tpl file, nothing shows up, Do I need a function in the acars.php module ? Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted April 3, 2011 Moderators Report Share Posted April 3, 2011 OK you have to load the schedule number, if your in the acars tpl then you can use the flight, that should work Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted April 3, 2011 Moderators Report Share Posted April 3, 2011 Or thinking about it if your creating a module use sql to get what you want. Quote Link to comment Share on other sites More sharing options...
James142 Posted April 3, 2011 Author Report Share Posted April 3, 2011 OK you have to load the schedule number, if your in the acars tpl then you can use the flight, that should work Sorry for my lack of php knowledge but how would I load the schedule number? Thanks Quote Link to comment Share on other sites More sharing options...
Moderators mark1million Posted April 3, 2011 Moderators Report Share Posted April 3, 2011 Ok let me have a play for 5 minutes and ill post the code, Where is it your putting or wanting to show the total distance, is it the acars.tpl 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.