# SQL Question

**URL:** <https://forum.phpvms.net/t/sql-question/3348>\
**Category:** phpVMS Legacy Support (v2/v5)\
**Created:** [September 4, 2010, 3:26am UTC](https://forum.phpvms.net/t/sql-question/3348 "2010-09-04T03:26:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AFVA\_Mitchell](https://forum.phpvms.net/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@AFVA\_Mitchell](https://forum.phpvms.net/u/AFVA_Mitchell)\
**Post date:** [September 4, 2010, 3:26am UTC](https://forum.phpvms.net/t/sql-question/3348/1 "2010-09-04T03:26:27Z")

</div>

I want to modify:

```
public static function getAircraftInfo($reg)
           {
               $reg = DB::escape($reg);

               return DB::get_row('SELECT * FROM '.TABLE_PREFIX.'aircraft 
                                   WHERE `registration` ='.$reg
                                   );
           }

```

so it will return the hours as well..

I have no idea how I am going to this so can someone please provide the code.

Thanks,

Mitch

---

<div class="post-metadata">

**Author:** ![simpilot](https://forum.phpvms.net/user_avatar/forum.phpvms.net/simpilot/32/26_2.png) [@simpilot](https://forum.phpvms.net/u/simpilot)\
**Post date:** [September 4, 2010, 5:09am UTC](https://forum.phpvms.net/t/sql-question/3348/2 "2010-09-04T05:09:33Z")

</div>

There is no record for total flight hours for an aircraft in the aircraft table, or anywhere else. You will need to create a sql call to the pireps table to get the total hours for an aircraft. Something like -\>

```
public function get_AircraftHours($id) {

           $query = 'SELECT SUM(flighttime) AS total FROM '.TABLE_PREFIX."pireps WHERE aircraft='$id'";

           $result = DB::get_row($query);

           return $result->total;
       }

```

The “$id” variable has to be the database id of the aircraft, not the registration as it is recorded that way in the pireps table.

---

<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:** [September 6, 2010, 4:36pm UTC](https://forum.phpvms.net/t/sql-question/3348/3 "2010-09-06T16:36:38Z")

</div>

There’s a function which does that already in statsdata

---

<div class="post-metadata">

**Author:** ![simpilot](https://forum.phpvms.net/user_avatar/forum.phpvms.net/simpilot/32/26_2.png) [@simpilot](https://forum.phpvms.net/u/simpilot)\
**Post date:** [September 6, 2010, 6:56pm UTC](https://forum.phpvms.net/t/sql-question/3348/4 "2010-09-06T18:56:16Z")

</div>

> There’s a function which does that already in statsdata

Sorry, but I don’t see 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:** [September 9, 2010, 11:40pm UTC](https://forum.phpvms.net/t/sql-question/3348/5 "2010-09-09T23:40:00Z")

</div>

[http://docs.phpvms.net/api/codon\_core/StatsData.html#AircraftUsage](http://github.com/nshahzad/phpVMS/blob/master/core/common/StatsData.class.php#L325)

[http://github.com/ns…class.php#L325](http://github.com/nshahzad/phpVMS/blob/master/core/common/StatsData.class.php#L325)

---

<div class="post-metadata">

**Author:** ![simpilot](https://forum.phpvms.net/user_avatar/forum.phpvms.net/simpilot/32/26_2.png) [@simpilot](https://forum.phpvms.net/u/simpilot)\
**Post date:** [September 10, 2010, 1:18am UTC](https://forum.phpvms.net/t/sql-question/3348/6 "2010-09-10T01:18:31Z")

</div>

Ah, I see said the blind man.
