Jump to content

Code to access database fields


t_bergman

Recommended Posts

  • Moderators

Open PilotData.class.php and add the following function at the end before the last bracket closes:


public function TotalFlightsByPilot()
{
$pilotid = Auth::$userinfo->pilotid;
$sql = "SELECT * FROM phpvms_pireps WHERE pilotid = '$pilotid'";
return DB::get_results($sql);
}

Then if you need to access the flights use the following:


<p> Total flight by pilot: <?php echo count( PilotData::TotalFlightsByPilot()) ;?></p>

Let us know what happens. ;)

Link to comment
Share on other sites

Open PilotData.class.php and add the following function at the end before the last bracket closes:


public function TotalFlightsByPilot()
{
$pilotid = Auth::$userinfo->pilotid;
$sql = "SELECT * FROM phpvms_pireps WHERE pilotid = '$pilotid'";
return DB::get_results($sql);
}

Then if you need to access the flights use the following:


<p> Total flight by pilot: <?php echo count( PilotData::TotalFlightsByPilot()) ;?></p>

Let us know what happens. ;)

This is perfect, I can also modify this to access a lot more.

Link to comment
Share on other sites

Open PilotData.class.php and add the following function at the end before the last bracket closes:


public function TotalFlightsByPilot()
{
$pilotid = Auth::$userinfo->pilotid;
$sql = "SELECT * FROM phpvms_pireps WHERE pilotid = '$pilotid'";
return DB::get_results($sql);
}

Then if you need to access the flights use the following:


<p> Total flight by pilot: <?php echo count( PilotData::TotalFlightsByPilot()) ;?></p>

Let us know what happens. ;)

This code works perfect for the total flight by pilots, I am trying to amend it to access aircraft data. I am building a module which will display data from the aircraft table.

My code from the php file is

public function FleetDetails($id)

{

if(!Auth::LoggedIn())

{

$this->set('message', 'You must be logged in to access this feature!');

$this->render('core_error.tpl');

return;

}

$id = self::AircraftInfo($sql);

$this->render('CrewResourceCenter/CRCFleetDetail.tpl');

$aircraftid = OperationsData::getAircraftInfo($id);

}

public static function AircraftInfo()

{

$sql = "SELECT * FROM phpvms_aircraft WHERE id = '$aircraftid'";

return DB::get_results($sql);

}

The tpl file is

<a href="http://www.hphvirtual.com/site/index.php/CrewResourceCenter/Fleet">Back to Fleet</a>

<p style="text-align:left; font-family:Impact, Haettenschweiler, Arial Narrow Bold, sans-serif; color:black; font-size:medium; line-height: 0px;">Fleet Datails</p>

<div id="CRCFleet">

<?php $id = $aircraftid; ?>

<table border="1">

<tr>

<th width="800px"><?php echo $aircraftid->fullname; ?></th>

</tr>

</table>

<table border="1">

<tr>

<th width="100px">Status</th>

<td width="100px"></td>

<th width="100px">Type</th>

<td width="100px"><?php echo $aircraft->name; ?></td>

<th width="100px">Registration</th>

<td width="100px"><?php echo $aircraft->registration; ?></td>

<th width="100px">Flight Hours</th>

<td width="100px"><?php echo $aircraft->totaltime; ?></td>

</tr>

</table>

</div>

I am new to php programming and this might be a little above my head. Basically I am trying to display individual aircraft statistics when access from http://www.hphvirtual.com/site/index.php/CrewResourceCenter/FleetDetails/1, the number correlating to the id in the aircraft table. Thanks.

Link to comment
Share on other sites

  • Moderators

Okay. First off do you know how to create a module in phpVMS?

Secondly, in first stack of codes, where are they located right now. This is important.

Third, variable "$id" where do you get the value for it? where is the rest of the code?

Forth, in second stack of codes, you're missing a loop to go through the results back from data base.

Fifth, You have a lot of issues with your code to resolve.

Link to comment
Share on other sites

Okay. First off do you know how to create a module in phpVMS?

Yes, I do know how to create a module with phpVMS, I'll admit that I am new to it however.

Secondly, in first stack of codes, where are they located right now. This is important.

What do you mean by stack of codes? The module folder has been created in both the modules and template folders.

Third, variable "$id" where do you get the value for it? where is the rest of the code?

$id is the variable for the id column in the aircraft table, not sure where the rest of the code is, I think I might have to create it.

Forth, in second stack of codes, you're missing a loop to go through the results back from data base.

The intention is only to display the information for one aircraft, is a loop needed?

Fifth, You have a lot of issues with your code to resolve.

I am aware.

Link to comment
Share on other sites

  • Moderators

Sorry didn't mean to be rude. :)

In order to display the results only for one aircraft, you'll need to pass the id of the aircraft to the function and the function will return only one record and that case the loop is not needed but if you have a table for all your aircraft then you'll definitely need a loop because the results will not be just one record.

What I understood from your question is that you want to have a fleet page with all the info for each aircraft if I'm not wrong. :)

Link to comment
Share on other sites

Sorry didn't mean to be rude. :)

In order to display the results only for one aircraft, you'll need to pass the id of the aircraft to the function and the function will return only one record and that case the loop is not needed but if you have a table for all your aircraft then you'll definitely need a loop because the results will not be just one record.

What I understood from your question is that you want to have a fleet page with all the info for each aircraft if I'm not wrong. :)

Thats quite ok, I probably took it a bit harsher than I should have, the one downside to forums is that you only see text. I think I may have found some code to get this started. Thanks for the help.

Link to comment
Share on other sites

Open PilotData.class.php and add the following function at the end before the last bracket closes:


public function TotalFlightsByPilot()
{
$pilotid = Auth::$userinfo->pilotid;
$sql = "SELECT * FROM phpvms_pireps WHERE pilotid = '$pilotid'";
return DB::get_results($sql);
}

Then if you need to access the flights use the following:


<p> Total flight by pilot: <?php echo count( PilotData::TotalFlightsByPilot()) ;?></p>

Let us know what happens. ;)

This is so inefficient, use this instead:


public function TotalFlightsByPilot()
{
$pilotid = Auth::$userinfo->pilotid;
$sql = "SELECT COUNT(pirepid) as count FROM ".TABLE_PREFIX."pireps WHERE pilotid = '$pilotid'";
$ret = DB::get_results($sql);
return $ret->count;
}


<p>Total flight by pilot: <?php echo PilotData::TotalFlightsByPilot(); ?></p>

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