Jump to content

How to show 5 recent flights for a pilot


Daniboi

Recommended Posts

Hello once again!

Today, I got a problem because I want to view 5 most recent flights for a pilot in the pilot_public_profile.php file.

 

this is what I tried to add, but didn’t work, I just got a emty Array of the flights:

<?php echo PIREPData::getLastReports($pilot->pilotid, 5, PIREP_ACCEPTED);

The $pilot variable is the variable that is Main used in the file.

Link to comment
Share on other sites

26 minutes ago, PikoSim said:

Could be your id code id wrong. Can you check what result it is giving by using this

 

<?php echo json_encode($pilot) ?> 

 

if it is giving a result then probably you can use the object it is returning

 

Am I going to add that in the pilot_public_profile.php file?

Edited by Daniboi
Link to comment
Share on other sites

This is the code in PIREPData.class.php:

 

  public static function getLastReports($pilotid, $count = 1, $status = '') {

        if($pilotid == '') {
            return false;
        }

        $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'pireps
					WHERE pilotid=' . intval($pilotid);

        # Check it via the status
        if ($status != '') {
            $sql .= ' AND accepted=' . intval($status);
        }

        $sql .= ' ORDER BY submitdate DESC
					LIMIT ' . intval($count);

        if ($count == 1) return DB::get_row($sql);
        else  return DB::get_results($sql);
    }

 

Link to comment
Share on other sites

Understood what you are trying to do. Basically, getlatreports with 5 counts will return 5 row. Hence, you need to foreach loop. So here is the code i have provided for you. Once you get the idea of it, you can integrate it with your table or display it hwoever you like.
Code

 

 <?php 
   //echo json_encode(PIREPData::getLastReports($pilot->pilotid, 1, PIREP_ACCEPTED)); // This is to get the parameters of the results like pirepid, flighttime etc. Mark out to not use it.
                            
	 $getpireps = PIREPData::getLastReports($pilot->pilotid, 5, PIREP_ACCEPTED); // $getpireps will contain the counted pireps
     foreach($getpireps as $pirep)
     {
   		echo $pirep->pirepid; // Display results based on attribute. 
       echo $pirep->flighttime;
       echo $pirep->depicao;
       // and it goes on 
     }
                    
                    
 ?>

LEt me know if this works for you.

Link to comment
Share on other sites

Thank you @PikoSim!

this is what I did with what you helped me with, I am into php, but the phpvms is diffrent from what I am used to.

 

Picture

 

And @ProAvia, it wasn’t pilot Information site I would like to reach, I have already it and I just wanted to show the latest flights from that pilot.

Edited by Daniboi
Link to comment
Share on other sites

  • Administrators

Isn't the information at the bottom of that similar to the info you are looking for? The bottom section lists PIREP info for the specific pilot listed. While it shows every PIREP from that specific pilot, the code can probably be edited to only show the last 5 PIREPS.

 

Or are you only wanting to show the last 5 PIREPS - regardless of who submitted them?

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