# Newest Pilots Help

**URL:** <https://forum.phpvms.net/t/newest-pilots-help/4408>\
**Category:** phpVMS Legacy Support (v2/v5)\
**Created:** [March 31, 2011, 10:14pm UTC](https://forum.phpvms.net/t/newest-pilots-help/4408 "2011-03-31T22:14:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jimmy\_S](https://forum.phpvms.net/user_avatar/forum.phpvms.net/jimmy_s/32/43_2.png) [@Jimmy\_S](https://forum.phpvms.net/u/Jimmy_S)\
**Post date:** [March 31, 2011, 10:14pm UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/1 "2011-03-31T22:14:43Z")

</div>

Can I list my Newest Pilots by date instead of their number? My current pilot list jumps around quite a bit and instead of listing the newest pilots it is listing the last two pilot ID’s.

---

<div class="post-metadata">

**Author:** ![Nuclear](https://forum.phpvms.net/user_avatar/forum.phpvms.net/nuclear/32/90_2.png) [@Nuclear](https://forum.phpvms.net/u/Nuclear)\
**Post date:** [April 1, 2011, 2:16am UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/2 "2011-04-01T02:16:22Z")

</div>

How are you currently getting the recent pilots? The default template retrieves the records by descending pilotid. Since pilotid is an auto-increment field, it should return the latest pilots. You certainly can list them by date, but I’d have to see how you’re retrieving the records first.

---

<div class="post-metadata">

**Author:** ![Jimmy\_S](https://forum.phpvms.net/user_avatar/forum.phpvms.net/jimmy_s/32/43_2.png) [@Jimmy\_S](https://forum.phpvms.net/u/Jimmy_S)\
**Post date:** [April 1, 2011, 11:41pm UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/3 "2011-04-01T23:41:13Z")

</div>

> How are you currently getting the recent pilots? The default template retrieves the records by descending pilotid. Since pilotid is an auto-increment field, it should return the latest pilots. You certainly can list them by date, but I’d have to see how you’re retrieving the records first.

You are right I am using the the default template and the records are by descending pilotid. Reason that is not working for me is we had a server crash and rebuilt using phpVMS. Some of the pilots that returned wanted their old ID and I gave it to them. Now when we sign up new pilots they are being assigned ID’s that are between current pilots. Example I have 005 and several in the three hundreds. So the new pilots are assigned PID in between and only the last few PID’s show up, they are current pilots not new ones. Thanks!

---

<div class="post-metadata">

**Author:** ![Nuclear](https://forum.phpvms.net/user_avatar/forum.phpvms.net/nuclear/32/90_2.png) [@Nuclear](https://forum.phpvms.net/u/Nuclear)\
**Post date:** [April 2, 2011, 12:42am UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/4 "2011-04-02T00:42:19Z")

</div>

Well, one way to do it would be this:

Make a copy of the frontpage\_main.tpl from /core/templates/

Edit the new copy and replace this:

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

```

With this:

```
<?php
$query='SELECT * FROM phpvms_pilots ORDER BY joindate DESC LIMIT 5';
$pilots=DB::get_results($query);
foreach($pilots as $pilot)
{
	echo '<a href='.SITE_URL.'/index.php/profile/view/'.$pilot->pilotid.'>';
	echo PilotData::getPilotCode($pilot->code,$pilot->pilotid).' '.$pilot->firstname.' '.$pilot->lastname.'</a><br><br>';
}?>

```

Now place the edited file into your skins directory (/lib/skins/crystal/ if you’re using the default crystal skin).

That will show the 5 most recent pilots sorted by date starting with the most recent.

---

<div class="post-metadata">

**Author:** ![Jimmy\_S](https://forum.phpvms.net/user_avatar/forum.phpvms.net/jimmy_s/32/43_2.png) [@Jimmy\_S](https://forum.phpvms.net/u/Jimmy_S)\
**Post date:** [April 2, 2011, 11:28pm UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/5 "2011-04-02T23:28:55Z")

</div>

Thanks so much Michael!

---

<div class="post-metadata">

**Author:** ![UAL3626](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/u/ea666f/32.png) [@UAL3626](https://forum.phpvms.net/u/UAL3626)\
**Post date:** [April 2, 2011, 11:32pm UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/6 "2011-04-02T23:32:27Z")

</div>

I’m running into the same problem. What do I need to do in order to not show the duplicates. I have removed some of the original code and still get errors. This is the code I have now with yours that works but shows the duplicates.

\<?php

foreach($pilots as $pilot)

{

if($pilot-\>confirmed != 1)

continue;

?\>

\<p\>\<a href=“\<?php echo url(‘/profile/view/’.$pilot-\>pilotid);?\>”\>\<?php echo

PilotData::GetPilotCode($pilot-\>code, $pilot-\>pilotid). ’ ’ .$pilot-\>firstname . ’ ’ .

$pilot-\>lastname?\>\</a\>\</p\>

\<?php

}

?\>

\<?php

$query=‘SELECT \* FROM phpvms\_pilots ORDER BY joindate DESC LIMIT 5’;

$pilots=DB::get\_results($query);

foreach($pilots as $pilot)

{

echo ‘\<a href=’.SITE\_URL.‘/index.php/profile/view/’.$pilot-\>pilotid.‘\>’;

echo PilotData::getPilotCode($pilot-\>code,$pilot-\>pilotid).’ '.$pilot-

\>firstname.’ ‘.$pilot-\>lastname.’\</a\>\<br\>\<br\>';

}?\>

---

<div class="post-metadata">

**Author:** ![Nuclear](https://forum.phpvms.net/user_avatar/forum.phpvms.net/nuclear/32/90_2.png) [@Nuclear](https://forum.phpvms.net/u/Nuclear)\
**Post date:** [April 3, 2011, 1:37am UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/7 "2011-04-03T01:37:43Z")

</div>

Your welcome, Jimmy. Glad you got it working.

---

<div class="post-metadata">

**Author:** ![Nuclear](https://forum.phpvms.net/user_avatar/forum.phpvms.net/nuclear/32/90_2.png) [@Nuclear](https://forum.phpvms.net/u/Nuclear)\
**Post date:** [April 3, 2011, 1:39am UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/8 "2011-04-03T01:39:18Z")

</div>

> I’m running into the same problem. What do I need to do in order to not show the duplicates. I have removed some of the original code and still get errors. This is the code I have now with yours that works but shows the duplicates.
> 
> \<?php
> 
> foreach($pilots as $pilot)
> 
> {
> 
> if($pilot-\>confirmed != 1)
> 
> continue;
> 
> ?\>
> 
> \<p\>\<a href=“\<?php echo url(‘/profile/view/’.$pilot-\>pilotid);?\>”\>\<?php echo
> 
> PilotData::GetPilotCode($pilot-\>code, $pilot-\>pilotid). ’ ’ .$pilot-\>firstname . ’ ’ .
> 
> $pilot-\>lastname?\>\</a\>\</p\>
> 
> \<?php
> 
> }
> 
> ?\>
> 
> \<?php
> 
> $query=‘SELECT \* FROM phpvms\_pilots ORDER BY joindate DESC LIMIT 5’;
> 
> $pilots=DB::get\_results($query);
> 
> foreach($pilots as $pilot)
> 
> {
> 
> echo ‘\<a href=’.SITE\_URL.‘/index.php/profile/view/’.$pilot-\>pilotid.‘\>’;
> 
> echo PilotData::getPilotCode($pilot-\>code,$pilot-\>pilotid).’ '.$pilot-
> 
> \>firstname.’ ‘.$pilot-\>lastname.’\</a\>\<br\>\<br\>';
> 
> }?\>

You should remove this part:

```
<?php

foreach($pilots as $pilot)
{
if($pilot->confirmed != 1)
continue;
?>

<p><a href="<?php echo url('/profile/view/'.$pilot->pilotid);?>"><?php echo

PilotData::GetPilotCode($pilot->code, $pilot->pilotid). ' ' .$pilot->firstname . ' ' .

$pilot->lastname?></a></p>
<?php
}
?>

```

If you only want to show pilots who have been confirmed, change this:

```
$query='SELECT * FROM phpvms_pilots ORDER BY joindate DESC LIMIT 5';

```

To this:

```
$query='SELECT * FROM phpvms_pilots WHERE confirmed=1 ORDER BY joindate DESC LIMIT 5';

```

I should have also noted - if you don’t want to show the newest 5 pilots, you can change ‘LIMIT 5’ to however many pilots you want to display.

---

<div class="post-metadata">

**Author:** ![nabeel](https://forum.phpvms.net/user_avatar/forum.phpvms.net/nabeel/32/2971_2.png) [@nabeel](https://forum.phpvms.net/u/nabeel)\
**Post date:** [April 3, 2011, 5:26am UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/9 "2011-04-03T05:26:12Z")

</div>

> If you only want to show pilots who have been confirmed, change this:
> 
> $query=‘SELECT \* FROM phpvms\_pilots ORDER BY joindate DESC LIMIT 5’;
> 
> To this:
> 
> $query=‘SELECT \* FROM phpvms\_pilots WHERE confirmed=1 ORDER BY joindate DESC LIMIT 5’;
> 
> I should have also noted - if you don’t want to show the newest 5 pilots, you can change ‘LIMIT 5’ to however many pilots you want to display.

Don’t use raw SQL, use the API for these queries:

```
$pilots = PilotData::getLatestPilots (10); // gets the last 10 pilots

```

See my sig for API listings.

---

<div class="post-metadata">

**Author:** ![Nuclear](https://forum.phpvms.net/user_avatar/forum.phpvms.net/nuclear/32/90_2.png) [@Nuclear](https://forum.phpvms.net/u/Nuclear)\
**Post date:** [April 3, 2011, 7:29am UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/10 "2011-04-03T07:29:52Z")

</div>

Nabeel, is of course right, but I do have a question:

> Don’t use raw SQL, use the API for these queries:

I understand the API exists to deal with most everything. but what’s the problem with using raw SQL? Beside the fact that it’s raw SQL? I do get it, but I find it much easier to use raw SQL (assuming that there isn’t an API call for it…)

---

<div class="post-metadata">

**Author:** ![nabeel](https://forum.phpvms.net/user_avatar/forum.phpvms.net/nabeel/32/2971_2.png) [@nabeel](https://forum.phpvms.net/u/nabeel)\
**Post date:** [April 4, 2011, 4:19am UTC](https://forum.phpvms.net/t/newest-pilots-help/4408/11 "2011-04-04T04:19:48Z")

</div>

> Nabeel, is of course right, but I do have a question:
> 
> I understand the API exists to deal with most everything. but what’s the problem with using raw SQL? Beside the fact that it’s raw SQL? I do get it, but I find it much easier to use raw SQL (assuming that there isn’t an API call for it…)

If there isn’t an API call, then you can use SQL, but do let me know so I can add it in. But for calls where an API method can be used, it’s best to use it, since it’s the safest way for when there are changes in the database or how things work, they’ll be invisible to you. For instance, there have been some changes to financials between the last two versions and this next one, so using raw SQL might just stop working. In 2.1 there were huge changes in how the basic queries were done and organized, and a few columns were removed (like flighttime going to flighttime\_stamp), you wouldn’t notice.

The other reason is the API implements some level of caching, so that database heavy queries (especially ones having to do with statistics, which can potentially go through thousands of records), are cached for a sensible amount of time, so they don’t unnecessarily tax your server. So unless you implement those cache read/writes yourself (which isn’t difficult to do), then you’re missing out on those optimizations.
