Jump to content

Recommended Posts

Posted

Ok, I really don't understand the workings of phpvms to try and do my own modules. So, I am asking for some guidance on one of my old sites stats pages.....

Here is my original code of an html page. It basically showed the amount of hours pilots had per aircraft. I am hoping someone can sort of guide me in how/what I could do to make this function in phpvms.

I used to pull all the data from the sql database, and obviously, you can tell I was doing it the long/hard way.

I think I get confused by how to grab the data, how to add the data together from different tables, etc. inside the phpvms environment. I would really like to understand phpvms so I can help, rather than asking questions all the time and feeling stupid :(

<body>
<?
print "<center>";
print "<b><font size=+3 color=#D86C4D>$callsign Fleet Stats</font></b><br>";
print "<hr width=800 align=center>";

$conn = mysql_connect( "canadianclassicairlines.com", "******", "******" );
mysql_select_db( "******_pireps" );

$query = "SELECT callsign, equipment, ROUND((SUM(time_to_sec(duration))/3600),2) AS block, COUNT(duration) AS flights FROM reports WHERE callsign = '$callsign' GROUP BY equipment"; 

$result = mysql_query($query) or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th>Aircraft</th> <th>Flights</th> <th>Hours</th> <th>Certified</th></tr>";

while($row = mysql_fetch_array($result)){

   echo "<tr><td align=left>";    
echo $row['equipment'];
echo "</td><td align=center>";
echo $row['flights'];
echo "</td><td align=center>";
echo $row['block'];
echo "</td><td align=center>";
 $var1 = '<img src="../pics/misc/orangerank.gif">';  
    if($row['block']>9.9 && $row['equipment']=='DC3'){
    echo $var1;
 }if($row['block']>9.9 && $row['equipment']=='DC6'){
    echo $var1;
    }if($row['block']>99.9 && $row['equipment']=='B737-200'){
    echo $var1;
 }if($row['block']>124.9 && $row['equipment']=='B727-100'){
    echo $var1;
 }if($row['block']>124.9 && $row['equipment']=='B727-200'){
    echo $var1;
 }if($row['block']>159.9 && $row['equipment']=='DC8-43'){
    echo $var1;
 }if($row['block']>159.9 && $row['equipment']=='DC8-53'){
    echo $var1;
 }if($row['block']>159.9 && $row['equipment']=='DC8-55'){
    echo $var1;
 }if($row['block']>199.9 && $row['equipment']=='DC8-63'){
    echo $var1;
 }if($row['block']>274.9 && $row['equipment']=='DC10-10'){
    echo $var1;
 }if($row['block']>299.9 && $row['equipment']=='DC10-30'){
    echo $var1;
 }if($row['block']>499.9 && $row['equipment']=='B747-200'){
    echo $var1;
 }if($row['block']>39.9 && $row['equipment']=='ATR72-500'){
    echo $var1;
 }if($row['block']>59.9 && $row['equipment']=='CRJ-200'){
    echo $var1;
 }if($row['block']>74.9 && $row['equipment']=='BAe146-200'){
    echo $var1;
 }if($row['block']>124.9 && $row['equipment']=='B737-300'){
    echo $var1;
 }if($row['block']>124.9 && $row['equipment']=='B737-700'){
    echo $var1;
 }if($row['block']>149.9 && $row['equipment']=='B757-200'){
    echo $var1;
 }if($row['block']>299.9 && $row['equipment']=='B767-300'){
    echo $var1;
 }if($row['block']>399.9 && $row['equipment']=='MD11'){
    echo $var1;
 }if($row['block']>499.9 && $row['equipment']=='B747-400'){
    echo $var1;
}
echo "</td></tr>";

}
echo "</table>";
?>
<?

print "<center>";
print "<b><font size=+3 color=#D86C4D>$callsign Flights</font></b><br>";
print "<hr width=908 align=center>";

$query = "SELECT * FROM reports WHERE callsign = '$callsign' ORDER BY date, report_id";

$result = mysql_query($query) or die(mysql_error());

echo "<table border='1'>";
echo "<tr> <th><font color=#D86C4D>Date of Flight</font></th> <th><font color=#D86C4D>Dep Airport</font></th> <th><font color=#D86C4D>Arr Airport</font></th> <th><font color=#D86C4D>Aircraft Reg</font></th> <th><font color=#D86C4D>Aircraft Type</font></th> <th><font color=#D86C4D>Block Time</font></th>  <th><font color=#D86C4D>Fuel</font></th> <th><font color=#D86C4D>Distance</font></th> </tr>";

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['date'];
echo "</td><td>"; 
echo $row['origin_id'];
echo "</td><td>"; 
echo $row['destination_id'];
echo "</td><td>"; 
echo $row['registration'];
echo "</td><td>"; 
echo $row['equipment'];
echo "</td><td>"; 
echo $row['duration'];
echo "</td><td>"; 
echo $row['fuel'];
echo "</td><td>"; 
echo $row['distance'];
echo "</td></tr>"; 

} 

echo "</table>";
?>
     </p>
     <p align="center" class="style17"> </p>    </td>
 </tr>
 <tr>
   <td bgcolor="#C6C6C6"> </td>
   <td colspan="2" bgcolor="#C6C6C6"> </td>
 </tr>
 <tr>
   <td colspan="3" bgcolor="#C6C6C6"> </td>
 </tr>
</table>
</body>
</html>

Posted

Ok, I will try a different approach :)

If I was trying to get the pilot stats for flights and/or hours for aircraft type, for individual pilots, what would I be looking to code?!

  • Administrators
Posted

There are a few functions available in the native stats class of phpVMS.

StatsData.class.php::PilotAircraftFlownCounts($pilotid)

will get you an array of the aircraft that the pilot has flown and how many times he has flown each one.

StatsData.class.php::AircraftUsage()

will return an array that shows how many times each aircraft in the fleet has been flown on a route

To get other customized stats it would be much easier to build a data class within phpVMS, it would alread be connected to the database and would make things a lot easier on you.

Posted

StatsData.class.php::PilotAircraftFlownCounts($pilotid)

will get you an array of the aircraft that the pilot has flown and how many times he has flown each one.

Ok, lets say with this first example....I would add that to a page I create. Say a module I have created that the php codon extends part is done. So it knows there is a module. Then the .tpl file for said module has that line of code "StatsData.class.php::PilotAircraftFlownCounts($pilotid)" in it.

Then?? I create a table to display the results in?

Posted

Nabeel, I have read them, I just don't understand them. I know this may seem obvious to you and others, but not to me.

Let me try to get a grasp of this. Okay in the api docs example of:

$pilots = PilotData::getAllPilots();
foreach($pilots as $pilot)
{
echo "{$pilot->firstname} {$pilot->lastname}";
}

It says it will output the pilots name. Now when I am testing this in a module, all I get is

 firstname} {$pilot->lastname}"; } ?> 

. It doesn't echo the data, just what I typed in after

echo "

So I don't know what I am missing here. I think the more I read to understand phpvms, the more I am confused on how it works. Am I the only one?! :(

I want to be able to create some things on my own, instead of just using what others have created; but I am having a problem grasping it. I am not a programmer and when I created my old site, it was just basic html/sql stuff. And I still had to get some help with that stuff.

  • Administrators
Posted

Try replacing that line with:

echo $pilot->firstname.' '.$pilot->lastname;

It just looks like a syntax error.

Also I made a quick layout for a module to try to show the relationship of the three pieces (Model(data class), Controller(module files), View(templates)) here -> http://forum.phpvms.net/topic/4095-solved-with-many-thanks-coding-noob-need-help/page__view__findpost__p__27456 See what you think. I am also on msn most evenings (Eastern USA), feel free to add me.

Posted

Yes, I appreciate that info:

to try to show the relationship of the three pieces

I will try to experiment with that. I will also try to touch base with you on this through msn. Send me an IM on your id, I couldn't add you as "simpilot"?! Much appreciated :D

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