Creating a foreach loop with HTML table and database

Hi,

I am trying to create a foreach loop so that each entry from a MySQL is created on a new row in an HTML table. This is what I have:

[php]<?php foreach $aircraft as $aircraft( ?>

<?php echo $aircraft->registration ?> Last Check Next Due
<?php ) ?>[/php]

There is an alternative to the MySQL database - it’s a TPL file located in another file and that’s where the $aircraft and $registration tags come from.

And by the way, this is the error I get:

Warning: Invalid argument supplied for foreach() in /home/freshje1/public_html/testskin/core/templates/fleet_maintenance.tpl on line 1

$aircraft must be an array of Database results.

PHP Code must be like :

[php]

<?php foreach($aircraft as $itemAircraft){ ?> <?php } ?>
<?php echo $itemAircraft->registration ?> Last Check Next Due
[/php]

That did not work. Now there is no table ::slight_smile:

$aircraft must be an array of Database results.

Example of data of mysql
[php]

<?php $aircraft = array(); $sel = "SELECT name FROM tablaTest"; $res = mysql_query($sel); while($row=mysql_fetch_assoc($res)){ $aircraft[] = $row['name']; } ?> <?php foreach($aircraft as $itemAircraft){ ?> <?php } ?>
<?php echo $itemAircraft; ?> Last Check Next Due
[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service