php help

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

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 Like

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

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

By flight number: SchedulesData::findFlight($flightnum)

By flight id: SchedulesData::getSchedule($flightid)

Example:

$flightinfo=SchedulesData::findFlight($flightno);
$dist=$flightinfo->distance;

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

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 Like

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?

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 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

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).

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.

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 :confused: I was really looking forward to see this work aah well

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.

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 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?

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

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 :confused:

EDIT: I made it look like I was giving out to you, so I changed this reply

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 :confused:

Yeah I didn’t know that did I, I had never seen it, hence assumed it would be static.

Anyway, read my edit

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);
	}