Jump to content

A little code help please


nexissair

Recommended Posts

Afternoon All

I currently have on my site a static fleet page gouped by aircraft type, however as part of my quest to learn MVC and php I thought I would have a go at making it dynamic so that when I add an aircraft the page auto updates saving me loads of work in the long run.

So after an evening of browsing though phpvms files to see how it all ticks, and based on the public pilots list, grouped by hubs I made my class, module and tpl files. I had some success but not completely, the page gives me one group for each icao which is what I wanted, but it also gives me all the whole fleet repeated in each group! not just the aircraft specific to the group.

If this was an access database I know the answer, php is not access so I'm stuffed, could some of you php wizards please look over what I've done and let me know where I've gone wrong please, All said and done this was only a learning excersise with a useful out come, so its not the end of the world, but if I don't know where or why I've gone wrong I can't learn from it, I did do a search but nothing came up specific to the way I'm trying to do this.

My code is below:

FleetData Class

<?php
/**
* Karl Sawdy
*/

class FleetData extends CodonData
{

//Get ICAO's
public static function getAllicao()
{
$sql = 'SELECT DISTINCT icao, fullname FROM '.TABLE_PREFIX.'aircraft
WHERE enabled=1 ORDER BY `icao` ASC';

return DB::get_results($sql);
}

/**
* Get all of the aircraft
*/
public static function getAllAircraft()
{
$sql = "SELECT a.* FROM ".TABLE_PREFIX."aircraft a
WHERE a.enabled=1 ORDER BY a.registration";

return DB::get_results($sql);
}

}

Fleet module

<?php
/**
* Karl Sawdy
*/

class Fleet extends CodonModule
{


public function index()
{
// Get all aircraft types, and list aircraft by type
$alltypes = FleetData::GetAllicao();

if(!$alltypes) $alltypes = array();

foreach($alltypes as $type)
{
$this->set('title', $type->fullname);
$this->set('icao', $type->icao);

$this->set('allaircraft', FleetData::getAllAircraft(array('a.icao'=>$type->icao)));

$this->render('fleet/fleet_list.tpl');
}
}
}

fleet list tpl

<div id="newshead">
<h3head><?php echo $title?></h3head>
</div>
<?php
if(!$allaircraft)
{
echo '<div id="news">There are no aircraft!</div>';
return;
}
?>
<div id="news">
<table id="tabledlist" class="tablesorter">
<thead>
<tr>
<th>Registration</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<?php
foreach($allaircraft as $aircraft)
{
?>
<tr>
<td><?php echo $aircraft->registration;?></td>
<td><?php echo $aircraft->fullname;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>

Many thanks All your help is much appreciated

Karl

  • Like 1
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...