Jump to content
Jeff

Recent 5 Flights

Recommended Posts

I'm trying to show a table of the 5 recent flights flown, and keep running into a brick wall here. Can someone please post the code to show the last 5 flight.

Flight Number - Departure Airport - Arrival Airport - Flight Time - Pilot - Landing %

Share this post


Link to post
Share on other sites

Here you go

<?php MainController::Run('PIREPS', 'RecentFrontPage', 5); ?>

or to just get the data

<?php

$count = 5;
$pireps = PIREPData::getRecentReportsByCount($count);

?>

Share this post


Link to post
Share on other sites

Jeff, I'm trying to create a table to place under the map on my home page that shows the last 5 flights flown. kind of like the one on this page The one that says latest arrivals.

Share this post


Link to post
Share on other sites

try this

<?php
$count = 5;
$pireps = PIREPData::getRecentReportsByCount($count);
?>

<table>
  <thead>
    <tr>
      <th>Flight #</th>
      <th>Departure</th>
      <th>Arrival</th>
      <th>Duration</th>
      <th>Pilot</th>
      <th>Landing Rate</th>
    </tr>
   </thead>
   <tbody>

<?php

if(count($pireps) > 0)
{
 foreach ($pireps as $pirep)
 {
   $pilotinfo = PilotData::getPilotData($pirep->pilotid);
   $pilotid = PilotData::getPilotCode($pilotinfo->code, $pilotinfo->pilotid); 

   echo '<tr>';
   echo '<td>'.$pirep->code.$pirep->flightnum.'</td>';
   echo '<td>'.$pirep->depicao.'</td>';
   echo '<td>'.$pirep->arricao.'</td>';
   echo '<td>'.$pirep->flighttime.'</td>';
   echo '<td>'.$pilotid.' '.$pilotinfo->firstname.' '.$pilotinfo->lastname.'</td>';
   echo '<td>'.$pirep->landingrate.'</td>';
   echo '</tr>';
 }
}
else
{
   echo '<tr><td>There are no recent flights!</td></tr>';
}
?>
  </tbody>
</table>

Edited by lorathon
EDITED to repair code - Code is 100%

Share this post


Link to post
Share on other sites

Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in /home/oneworld/public_html/lib/skins/crystal-II/frontpage_main.tpl on line 61

This is line 61
echo "</tr>";

Share this post


Link to post
Share on other sites

I fixed the above code.

Missing a semi-colon on the line above. Sorry about that.

echo "<td>'.$pirep->landingrate.'</td>";

Share this post


Link to post
Share on other sites

Parse error: syntax error, unexpected $end in /home/oneworld/public_html/lib/skins/crystal-II/frontpage_main.tpl on line 162

This is line 162
</div>

Here is the whole code for that page
<div id="mainbox">
<h3>Welcome To One World Virtual</h3>
<?php

// Show the News module, call the function ShowNewsFront
//	This is in the modules/Frontpage folder

MainController::Run('News', 'ShowNewsFront', 5);
?>
<?php
       $flights = PIREPData::getRecentReportsByCount(15);                                                                      
       $string = "";
       foreach($flights as $flight)
       {       
            $string = $string.$flight->depicao.'+-+'.$flight->arricao.',+';
       }                                                                       
       ?>
       <table>
         <tr>
           <th>LAST 15 FLIGHT LEGS</th>
         </tr>
         <tr>
           <td><p align="center"><img src="http://www.gcmap.com/map?P=<?php echo $string ?>&MS=bm&MR=240&MX=690x360&PM=pemr:diamond7:red%2b%22%25I%22:red&PC=%230000ff" /><br />
             Maps generated by the <a href="http://www.gcmap.com/">Great Circle Mapper</a> - copyright © <a href="http://www.kls2.com/~karl/">Karl L. Swartz</a>.</p></td>
             </tr>
                   </table>
                   <?php
$count = 5;
$pireps = PIREPData::getRecentReportsByCount($count);
?>

<table>
  <thead>
    <tr>
      <th>Flight #</th>
      <th>Departure</th>
      <th>Arrival</th>
      <th>Duration</th>
      <th>Pilot</th>
      <th>Landing Rate</th>
    </tr>
   </thead>
   <tbody>

<?php

if(count($pireps) > 0)
{
 foreach ($pireps as $pirep)
 {
   $pilotinfo = PilotData::getPilotData($pirep->pilotid);
   $pilotid = PilotData::getPilotCode($pilotinfo->code, $pilotinfo->pilotid); 

   echo "<tr>";
   echo "<td>'.$pirep->code.$pirep->flighnum.'</td>";
   echo "<td>'.$pirep->depicao.'</td>";
   echo "<td>'.$pirep->arricao.'</td>";
   echo "<td>'.$pirep->flighttime.'</td>";
   echo "<td>'.$pilotid.' '.$pilotinfo->firstname.' '.$pilotinfo->lastname.'</td>";
   echo "<td>'.$pirep->landingrate.'</td>";
   echo "</tr>";
 }
}
else
{
   echo "<tr><td>There are no recent flights!</td></tr>";
?>
  </tbody>
</table>


</div>

</div>


<div id="sidebar">
 <h3>Pilot Center</h3>


	<?php 
	/* 
	Quick example of how to see if they're logged in or not
	Only show this login form if they're logged in */
	if(Auth::LoggedIn() == false)
	{ ?>
		<form name="loginform" action="<?php echo url('/login'); ?>" method="post">
			<p>Log in to your pilot center or <a href="<?php echo url('/registration'); ?>">register</a><br />
		<input type="text" name="email" value="Email/Pilot ID" onClick="this.value=''" />
			</p>
			<p>
			  <input type="password" name="password" value="Password" />
		  </p>
			<p>
			  <input type="hidden" name="remember" value="on" />
			  <input type="hidden" name="redir" value="index.php/profile" />
			  <input type="hidden" name="action" value="login" />
			  <input type="submit" name="submit" value="Log In" />
		  </p>
 </form>
		<p>
		<?php
	}	
	/* End the Auth::LoggedIn() if */
	else /* else - they're logged in, so show some info about the pilot, and a few links */
	{

	/*	Auth::$userinfo has the information about the user currently logged in
		We will use this next line - this gets their full pilot id, formatted properly */
	$pilotid = PilotData::GetPilotCode(Auth::$userinfo->code, Auth::$userinfo->pilotid);
	?>
	    <strong>Pilot ID: </strong> <?php echo $pilotid ; ?>
	    <strong>Rank: </strong><?php echo Auth::$userinfo->rank;?><br />
	    <strong>Total Flights: </strong><?php echo Auth::$userinfo->totalflights?>, <strong>Total Hours: </strong><?php echo Auth::$userinfo->totalhours;?>
	<br /><?php
	} /* End the else */
	?>

 </p>
		<p>
		  <?php MainController::Run('Mail', 'checkmail'); ?>
		</p>
<h3>Recent Reports</h3>

<?php MainController::Run('PIREPS', 'RecentFrontPage', 5); ?>

<h3>Newest Pilots</h3>

<p>
  <?php MainController::Run('Pilots', 'RecentFrontPage', 5); ?>
 </p>
<h3>Airline Stats</h3>
<p><strong>Total Schedules: </strong><?php echo StatsData::totalschedules(); ?></p>
<p><strong>Total Aircraft: </strong><?php echo StatsData::TotalAircraftInFleet(); ?></p>
<p><strong>Total Pilots: <?php echo StatsData::PilotCount(); ?></strong></p>
<p><strong>Miles Flown: </strong><?php echo StatsData::TotalMilesFlown(); ?></p>
       <p><strong>Total Flights Flown: </strong><?php echo StatsData::TotalFlights(); ?></p>
       <p><strong>Total Hours Flown: </strong><?php echo StatsData::TotalHours(); ?></p>
       <p><strong>Passengers Carried: </strong><?php echo StatsData::TotalPaxCarried(); ?></p>
       <p><strong>Fuel Burned (lbs.): </strong><?php echo StatsData::TotalFuelBurned(); ?></p>
       <p><strong>Avg Landing Rate: </strong><?php echo ''.round(TouchdownStatsData::airline_average('airline'), 2); ?></p>
       <p><strong>Total Flights Today: </strong><?php echo StatsData::totalflightstoday(); ?></p>
       <p><strong>Total Cargo Carried: </strong><?php echo StatsData::TotalCargoCarried(); ?>
<h3>Users Online</h3>
<?php
      foreach($usersonline as $pilot)  

       {

               echo "<p>";
               echo '<img src="'.Countries::getCountryImage($pilot->location).'" alt="'.Countries::getCountryName($pilot->location).'" />';
               echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid). ' ' .$pilot->firstname . ' ' . $pilot->lastname; 
               echo "</p>";

       }


       ?>
              <br />
              Have <?php echo count($usersonline);?> Pilots Online.
              <h3 class="style3">Guests Online </h3>
              <p class="txt-red10"> Have <?php echo count($guestsonline);?> Guests Online.</div>
</div>

Share this post


Link to post
Share on other sites

After this

echo "<tr><td>There are no recent flights!</td></tr>";

I forgot to close the else

}

I will repair the original code

Share this post


Link to post
Share on other sites

@ Gabriel

I modified my original post so the code there is correct. It is just a simple table for the 5 most recent flights.

Share this post


Link to post
Share on other sites

I can not get this to show the full flight Number. As we have 5 Wings(Airlines) it only show the letters of the Wings(Airlines) but not the actual flight number. EX. VMC1001 just will show as VMC or 57V0401-1 will only show 57V. any Ideas? :D

thanks

Share this post


Link to post
Share on other sites

I can not get this to show the full flight Number. As we have 5 Wings(Airlines) it only show the letters of the Wings(Airlines) but not the actual flight number. EX. VMC1001 just will show as VMC or 57V0401-1 will only show 57V. any Ideas? :D

thanks

Try it on more time. I had a type on the flightnum call. Original code is repaired again :D

Share this post


Link to post
Share on other sites

Hi guys. I know this post is real old and I hate to necro post, but I must.

I have been itching to add this for a long time but never got around to it. I used the code posted above and it shows up on my site but with some errors.

When it outputs the data to the table it shows up like this :

tableerror.jpg

I have been trying to fix it, but not sure what is going on. Would love some guiding light.

Thanks in advance.

Ray

Share this post


Link to post
Share on other sites

Fixed! I got rid of all the " and replaced with ' .

Now I want to get rid of the landing rate and add Status. So it would show Pending, Accepted, Rejected etc,etc.

I tried nabbing the code from the viewall_pireps.tpl but it just tossed me out a syntax error.

Here is the code tossing the error at me. It is the first div line where it says accepted.

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/xxxxxx/public_html/xxxxxx/lib/skins/brilliancev1/frontpage_main.tpl on line 87

<?php

if(count($pireps) > 0)
{
 foreach ($pireps as $pirep)
 {
   $pilotinfo = PilotData::getPilotData($pirep->pilotid);
   $pilotid = PilotData::getPilotCode($pilotinfo->code, $pilotinfo->pilotid); 

   echo '<tr>';
   echo '<td><center>'.$pirep->code.$pirep->flightnum.'</center></td>';
   echo '<td><center>'.$pirep->depicao.'</center></td>';
   echo '<td><center>'.$pirep->arricao.'</center></td>';
   echo '<td><center>'.$pirep->flighttime.'</center></td>';
   echo '<td><center>'.$pilotid.' '.$pilotinfo->firstname.' '.$pilotinfo->lastname.'</center></td>';
   echo '<td><?php

	if($pirep->accepted == PIREP_ACCEPTED)
		echo '<div id="success">Accepted</div>';
	elseif($pirep->accepted == PIREP_REJECTED)
		echo '<div id="error">Rejected</div>';
	elseif($pirep->accepted == PIREP_PENDING)
		echo '<div id="error">Pending</div>';
	elseif($pirep->accepted == PIREP_INPROGRESS)
		echo '<div id="error">In Flight</div>';

	?></td>';
   echo '</tr>';
 }
}
else
{
   echo '<tr><td>There are no recent flights!</td></tr>';
}
?>

It is no biggie if I do not get it to work since it is on a dev site only, but would be real nice to get the flight status to work.

And please do ignore all of the center and end center tags. I know they are not right. I just hadn't got to do it the right way yet. ;)

Share this post


Link to post
Share on other sites

I also changed the original code to single quotes. Not sure why I put the doubles in there. Brain Fart?

Share this post


Link to post
Share on other sites

You have an extra set of php tags in the file

echo '<td><?php 

and

?></td>';

I got rid of the extra stuff you suggested and I still get the same exact error. :D

Share this post


Link to post
Share on other sites

I also changed the original code to single quotes. Not sure why I put the doubles in there. Brain Fart?

Oh stuff like that happens from time to time eh? ;) No biggie. Was a quick easy fix.

Share this post


Link to post
Share on other sites

Anyone got a working copy of this they would care to share? Meaning just for flight status. I got all the rest of it working smoothly. I don't need the touchdown rate so I scrapped it in hopes of getting the flight status in there instead. Like Accepted, pending, Rejected.

Share this post


Link to post
Share on other sites
<?php
$count = 5;
$pireps = PIREPData::getRecentReportsByCount($count);
?>

<table>
  <thead>
    <tr>
      <th>Flight #</th>
      <th>Departure</th>
      <th>Arrival</th>
      <th>Duration</th>
      <th>Pilot</th>
      <th>Status</th>
    </tr>
   </thead>
   <tbody>

<?php

if(count($pireps) > 0)
{
 foreach ($pireps as $pirep)
 {
   $pilotinfo = PilotData::getPilotData($pirep->pilotid);
   $pilotid = PilotData::getPilotCode($pilotinfo->code, $pilotinfo->pilotid);

   if($pirep->accepted == '0') $status = 'PENDING';
   if($pirep->accepted == '1') $status = 'ACCEPTED';
   else $status = 'REJECTED'; 

   echo '<tr>';
   echo '<td>'.$pirep->code.$pirep->flightnum.'</td>';
   echo '<td>'.$pirep->depicao.'</td>';
   echo '<td>'.$pirep->arricao.'</td>';
   echo '<td>'.$pirep->flighttime.'</td>';
   echo '<td>'.$pilotid.' '.$pilotinfo->firstname.' '.$pilotinfo->lastname.'</td>';
   echo '<td>'.$status.'</td>';
   echo '</tr>';
 }
}
else
{
   echo '<tr><td>There are no recent flights!</td></tr>';
}
?>
  </tbody>
</table>

  • Like 1

Share this post


Link to post
Share on other sites

Just a quick question as I'm not a php wiz...

Is it possible to make the 'Flight#' field a link to view the actual pirep? I've tried using a <a href= but it keeps throwing up errors as I'm not sure how or where to place it in the data string. Cheers!

Share this post


Link to post
Share on other sites

With link to pirep report on flight number.

<?php
$count = 5;
$pireps = PIREPData::getRecentReportsByCount($count);
?>

<table>
  <thead>
    <tr>
      <th>Flight #</th>
      <th>Departure</th>
      <th>Arrival</th>
      <th>Duration</th>
      <th>Pilot</th>
      <th>Status</th>
    </tr>
   </thead>
   <tbody>

<?php

if(count($pireps) > 0)
{
 foreach ($pireps as $pirep)
 {
   $pilotinfo = PilotData::getPilotData($pirep->pilotid);
   $pilotid = PilotData::getPilotCode($pilotinfo->code, $pilotinfo->pilotid);

   if($pirep->accepted == '0') $status = 'PENDING';
   if($pirep->accepted == '1') $status = 'ACCEPTED';
   else $status = 'REJECTED'; 

   echo '<tr>';
   echo '<td><a href="'.SITE_URL.'/index.php/pireps/viewreport/'.$pirep->pirepid.'">'.$pirep->code.$pirep->flightnum.'</a></td>';
   echo '<td>'.$pirep->depicao.'</td>';
   echo '<td>'.$pirep->arricao.'</td>';
   echo '<td>'.$pirep->flighttime.'</td>';
   echo '<td>'.$pilotid.' '.$pilotinfo->firstname.' '.$pilotinfo->lastname.'</td>';
   echo '<td>'.$status.'</td>';
   echo '</tr>';
 }
}
else
{
   echo '<tr><td>There are no recent flights!</td></tr>';
}
?>
  </tbody>
</table>

Share this post


Link to post
Share on other sites

That's brilliant - thanks!

What was throwing me was the apostrophies ( ' ) - I just couldn't seem to get the href in the right place!

Must be nice to be able to know php... ;) Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×