Jump to content

php help


James142

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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 by James142
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Thanks for the suggestions anyways!

May I ask are you talking about the javascript in the live map or in the progress bar?

Link to comment
Share on other sites

Javascript in the acars map. I had assumed you were doing a static percentage bar :P

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

Link to comment
Share on other sites

Javascript in the acars map. I had assumed you were doing a static percentage bar :P

Nope :P 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 :P

Edited by James142
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...