Jump to content

[SOLVED with many thanks] Coding noob need help


Recommended Posts

Posted

Ok I have spent a month now trying to write my own module...

I simply want a list of all the airports and its details (name, icao, and chartlink)

I have even tried using an existing class (operations data) and I just can't figure it out.

I have a book on php code, but it seems to be different from the VMS.

I have used this:

<h2>List of Current Airports / Outposts </h2>

<table id="tabledlist" class="tablesorter">

<thead>

<tr><td><b>Airport Name</b></td><td><b>IACO</b></td><td><b>Chartlink</b></td>

</tr>

</thead>

<tbody>

<?php $all_airports = OperationsData::getAllAirports();?>

<?php foreach ($all_airports as $airport)

{

?>

<tr>

<td><?php echo $airport->name; ?></td>

<td><?php echo $airport->iaco; ?></td>

<td><?php echo $aircraft->chartlink; ?></td>

</tr>

<?php

}

?>

</tbody>

</table>

and get a table with only the aiport name.

The module file simply calls the template.

<?php

class airportlist extends CodonModule

{

public function index()

{

Template::Show('airportlist.tpl');

}

}

?>

My original class (that I gave up on and have now used the Operation Data one was:

class airportlistdata extends CodonData

{

public static function getallairports()

{

$sql = 'SELECT * FROM '.TABLE_PREFIX.'airports';

return DB::get_row($sql);

}

}

I was hoping that someone would be able to give me a very simple example of a class, module, and template so that I can reverse engineer it and figure this all out.

I would be EXTREMEMLY greatful.

I have tried reverse engineering the existing ones, but they all have too many variables built into them and it confuses me.

so again....a simple class, module, and template for an airport table (no variables) would be most helpful.

I hope it not too much to ask, but as I say, I have been trying for about a month now and am about to give up.

  • Administrators
Posted

Here is an example that may help you out:

MyairportsData.class.php in root/core/common/

<?php

class MyairportsData extends CodonData  {

   function getmyairports()    {
       $query = 'SELECT * FROM '.TABLE_PREFIX.'airports';

       return DB::get_results($query);
   }
}

Myairports.php in root/core/modules/Myairports/

<?php

class Myairports extends CodonModule    {

   public function index()    {
       $this->set('myairports', MyairportsData::getmyairports());
       $this->show('myairports.tpl');
   }

}

myairports.tpl in root/core/templates/ or your skin folder

<?php
   foreach ($myairports as $myairport)
   {
       echo $myairport->icao.' - '.$myairport->name.' - '.$myairport->country.' - '.$myairport->lat.' - '.$myairport->lng.'<br />';
   }
?>

That should display all the airports in your database when you goto -> www.yoursite.com/index.php/Myairports B)

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