freshJet Posted July 21, 2011 Report Share Posted July 21, 2011 I am trying to create another aircraft list but with registrations and type only, for the maintenance module. I've got this: <?php foreach $aircraft as $aircraft( ?> <html> <table border="1"> <tr> <td width="200"><?php echo $aircraft->registration ?></td> <td width="200">Last Check</td> <td width="200">Next Due</td> </tr> </table> </html> <?php ) ?> But get: Warning: Invalid argument supplied for foreach() in /home/freshje1/public_html/testskin/core/templates/fleet_maintenance.tpl on line 1 Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 I am trying to create another aircraft list but with registrations and type only, for the maintenance module. I've got this: <?php foreach $aircraft as $aircraft( ?> <html> <table border="1"> <tr> <td width="200"><?php echo $aircraft->registration ?></td> <td width="200">Last Check</td> <td width="200">Next Due</td> </tr> </table> </html> <?php ) ?> But get: Warning: Invalid argument supplied for foreach() in /home/freshje1/public_html/testskin/core/templates/fleet_maintenance.tpl on line 1 Have you created a module file for the template, so you can pull the relevent aircraft data from the database? Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 Yes I've done all that. It's a PHP error. What's wrong with the code? Here's a link: http://www.freshjetvirtual.com/testskin/index.php/fleetmaintenance Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 Yes I've done all that. It's a PHP error. What's wrong with the code? Here's a link: http://www.freshjetvirtual.com/testskin/index.php/fleetmaintenance Got to be logged in to view Also, why have you got the <html></html> in the code? That should only be used once on a page, and it's in your layout.tpl and footer files. EDIT: worth doing a print_r to see if the aircraft data is actually available? Place this somewhere in the file: <?php print_r($aircraft);?> See what that shows Also try changing this <?php foreach $aircraft as $ac( ?> and then amend the $aircraft to $ac in the rest of the code. Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 Yes I've done all that. It's a PHP error. What's wrong with the code? Here's a link: http://www.freshjetvirtual.com/testskin/index.php/fleetmaintenance Got to be logged in to view Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 There is no data. It wouldn't let me add the aircraft. That shouldn't come back with this though - it's an error in the code... Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 Just noticed, you are using () instead of {}. Try changing them. Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 If there was nothing showing with the print_r, then it's a problem with the module file and not the template file. Can you post that up and we can get a better idea. Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 Didn't work. Keep getting errors. Now got: Parse error: syntax error, unexpected '{', expecting '(' in /home/freshje1/public_html/testskin/core/templates/fleet_maintenance.tpl on line 1 <?php foreach {$aircraft as $ac}?> <table border="1"> <tr> <td width="200"><?php echo $ac->registration ?></td> <td width="200">Last Check</td> <td width="200">Next Due</td> </tr> </table> <?php } ?> Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 You can sign up if you like, it's a test site anyway, so I locked it so no one can nick anything. Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 My bad, should have posted the code. Here's what I meant: <?php foreach ($aircraft as $ac){?> <table border="1"> <tr> <td width="200"><?php echo $ac->registration ?></td> <td width="200">Last Check</td> <td width="200">Next Due</td> </tr> </table> <?php }; ?> Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 OK that cleared up slightly, still something wrong with line 1: Warning: Invalid argument supplied for foreach() in /home/freshje1/public_html/testskin/core/templates/fleet_maintenance.tpl on line 1 Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 Is $aircraft correct? Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 OK that cleared up slightly, still something wrong with line 1: Warning: Invalid argument supplied for foreach() in /home/freshje1/public_html/testskin/core/templates/fleet_maintenance.tpl on line 1 That code should work. How are you calling the aircraft data from the db? It's saying invalid argument because there is no $aircraft data available. Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 How can I edit that error message then? Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 I've added it manually through phpMyAdmin but it won't show in the admin panel or on the site... Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 I've added it manually through phpMyAdmin but it won't show in the admin panel or on the site... When you create a new module (addon), you need to create a function to pull the data from the database using an sql query, or to use an existing function to pull the data. Then you can echo it out in the template (tpl) files. By the sounds of it, you're not pulling any data from the database in the module file, so there's nothing to display in the template file. Quote Link to comment Share on other sites More sharing options...
freshJet Posted July 21, 2011 Author Report Share Posted July 21, 2011 So how do I then? Quote Link to comment Share on other sites More sharing options...
stuartpb Posted July 21, 2011 Report Share Posted July 21, 2011 So how do I then? You should be able to pull the data for the aircraft using an existing function, I wrote my own for my fleet pages though. IIRC, the OperationsData.Class file has an existing function/query for pulling ac data. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.