Henrique Posted October 4, 2019 Report Share Posted October 4, 2019 How can I display the list of pilots on my external site? I'm using <?php include(/sytem/core/codon.config.php'); ?> ( it is working perfectly, but I just can't make the pilot list for my site. ) Quote Link to comment Share on other sites More sharing options...
Moderators ProSkyDesign Posted October 5, 2019 Moderators Report Share Posted October 5, 2019 (edited) On 10/4/2019 at 4:14 PM, Henrique said: How can I display the list of pilots on my external site? I'm using <?php include(/sytem/core/codon.config.php'); ?> ( it is working perfectly, but I just can't make the pilot list for my site. ) now you can access statics functions inside variables like: $pilots = PilotData::getAllPilots(); and then you can iterate the variable with a foreach loop. <?php foreach($pilots as $pilot) { echo $pilot->rank; } ?> Please, be careful including the codon config, include this in top of the file, avoiding headers errors. Edited October 5, 2019 by ProSkyDesign grammar errors Quote Link to comment Share on other sites More sharing options...
Henrique Posted October 7, 2019 Author Report Share Posted October 7, 2019 On 10/5/2019 at 5:39 PM, ProSkyDesign said: now you can access statics functions inside variables like: $pilots = PilotData::getAllPilots(); and then you can iterate the variable with a foreach loop. <?php foreach($pilots as $pilot) { echo $pilot->rank; } ?> Please, be careful including the codon config, include this in top of the file, avoiding headers errors. Message: Invalid argument supplied for foreach() Quote Link to comment Share on other sites More sharing options...
Henrique Posted October 7, 2019 Author Report Share Posted October 7, 2019 how can i put a table there? table in echo Quote Link to comment Share on other sites More sharing options...
Moderators ProSkyDesign Posted October 7, 2019 Moderators Report Share Posted October 7, 2019 (edited) 2 hours ago, Henrique said: how can i put a table there? table in echo Personally, I don't recommend to print HTML code with php, please use something like this. <?php if(!$pilots) { echo 'There are no pilots!'; return; } ?> <table class="tablesorter"> <thead> <tr> <th>Pilot ID</th> <th>Name</th> <th>Rank</th> <th>Flights</th> <th>Hours</th> </tr> </thead> <tbody> <tr> <?php foreach($pilots as $pilot) { ?> <td><a href="<?php echo url('/profile/view/'.$pilot->pilotid);?>"><?php echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid); ?></a></td> <td><?php echo $pilot->firstname . ' '. $pilot->lastname; ?></td> <td><img src="<?php echo $pilot->rankimage; ?>" alt="<?php echo $pilot->rank; ?>" /></td> <td><?php echo $pilot->totalflights; ?></td> <td><?php echo $pilot->totalflights; ?></td> <td><?php echo Util::AddTime($pilot->totalhours, $pilot->transferhours); ?></td> <?php } ?> </tr> </tbody> </table> Remember to declare $pilots variable first with your codon config. Edited October 7, 2019 by ProSkyDesign Quote Link to comment Share on other sites More sharing options...
Henrique Posted October 7, 2019 Author Report Share Posted October 7, 2019 17 hours ago, ProSkyDesign said: Personally, I don't recommend to print HTML code with php, please use something like this. <?php if(!$pilots) { echo 'There are no pilots!'; return; } ?> <table class="tablesorter"> <thead> <tr> <th>Pilot ID</th> <th>Name</th> <th>Rank</th> <th>Flights</th> <th>Hours</th> </tr> </thead> <tbody> <tr> <?php foreach($pilots as $pilot) { ?> <td><a href="<?php echo url('/profile/view/'.$pilot->pilotid);?>"><?php echo PilotData::GetPilotCode($pilot->code, $pilot->pilotid); ?></a></td> <td><?php echo $pilot->firstname . ' '. $pilot->lastname; ?></td> <td><img src="<?php echo $pilot->rankimage; ?>" alt="<?php echo $pilot->rank; ?>" /></td> <td><?php echo $pilot->totalflights; ?></td> <td><?php echo $pilot->totalflights; ?></td> <td><?php echo Util::AddTime($pilot->totalhours, $pilot->transferhours); ?></td> <?php } ?> </tr> </tbody> </table> Remember to declare $pilots variable first with your codon config. it worked, thank you very much. 1 Quote Link to comment Share on other sites More sharing options...
Moderators ProSkyDesign Posted October 7, 2019 Moderators Report Share Posted October 7, 2019 21 minutes ago, Henrique said: it worked, thank you very much. You’re welcome 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.