Ariel
July 31, 2016, 5:02am
1
Im trying to display the latest flight details of a pilots last flown flight.
Using this code
<?php echo $report->depicao; ?> <img src="/airplaneicon.png" alt=""> <?php echo $report->arricao; ?>
FLIGHT: <?php echo $report->code . $report->flightnum; ?>
AIRCRAFT: <?php echo $report->aircraft; ?>
DATE SUBMITTED: <?php echo date(DATE_FORMAT, $report->submitdate); ?>
but what i get is this
The airport ICAOs are correct and so is the flight number but the aircraft and date are either not what i want it to show or wrong. The aircraft assigned to that flight is the second aircraft on the database but i want it to display the aircraft name. As for the date I cant seem to understand where its getting it from if not from the last submitted PIREP.
Can anyone please let me know what im doing wrong!
Very much appreciated and thank you in advance!
web541
July 31, 2016, 8:02am
2
canāt remember what type of field the āsubmitdateā is, but you could try
<?php echo $report->depicao; ?> <img src="/airplaneicon.png" alt=""> <?php echo $report->arricao; ?>
FLIGHT: <?php echo $report->code . $report->flightnum; ?>
AIRCRAFT: <?php echo $report->aircraft; ?>
DATE SUBMITTED: <?php echo date(DATE_FORMAT, strtotime($report->submitdate)); ?>
or if that doesnāt work, do a
<?php echo print_r($report); ?>
And post what you have for the field
[submitdate] =>
What I use
<?php
$pirep = PIREPData::getRecentReportsByCount(1);
foreach($pirep as $p) {
echo $p->depicao.' - '.$p->arricao;
echo '<br />';
echo $p->code.$p->flightnum;
echo '<br />';
echo $p->aircraft;
echo '<br />';
echo date(DATE_FORMAT, $p->submitdate);
echo '<br />';
}
?>
1 Like
Ariel
July 31, 2016, 8:35pm
3
canāt remember what type of field the āsubmitdateā is, but you could try
<?php echo $report->depicao; ?> <?php echo $report->arricao; ?>
FLIGHT: <?php echo $report->code . $report->flightnum; ?>
AIRCRAFT: <?php echo $report->aircraft; ?>
DATE SUBMITTED: <?php echo date(DATE_FORMAT, strtotime($report->submitdate)); ?>
or if that doesnāt work, do a
<?php echo print_r($report); ?>
And post what you have for the field
[submitdate] =>
What I use
<?php
$pirep = PIREPData::getRecentReportsByCount(1);
foreach($pirep as $p) {
echo $p->depicao.' - '.$p->arricao;
echo ' ';
echo $p->code.$p->flightnum;
echo ' ';
echo $p->aircraft;
echo ' ';
echo date(DATE_FORMAT, $p->submitdate);
echo ' ';
}
?>
Hey web541,
Thanks a bunch for responding. I did end up changing the submit date with the first edit you suggested and that did correct the issue regarding the submitdate.
Now for the life of me i couldnt get the aircraft name to appear and though you did post what you use on your site i didnt want to use it with out giving it a few tries with other codes and suchā¦but that was to no avail.
I did, on a side note, used your āspoilerā code and that did the trick and want to thank you for showing your code. I did tweak it alittle just to not have too many echos and but either one works just fineā¦
<?php
$pirep = PIREPData::getRecentReportsByCount(1);
foreach($pirep as $p) {
echo '
'.$p->depicao.' <img src="/airplaneicon.png" alt=""> '.$p->arricao.'
FLIGHT: '.$p->code . $p->flightnum.'
AIRCRAFT: '.$p->aircraft.'
SUBMITTED: '.date(DATE_FORMAT, $p->submitdate).'
';
}
?>
All in all thank you for the help. I really appreciate it!! #lifesaver
Ariel
July 31, 2016, 8:46pm
4
Now i did try adding an ELSE section to the code so when a pilot doesnt have any flights (ex. new pilot) it will display something saying that there is no flights but i keep getting a syntax error.
Parse error : syntax error, unexpected āelseā (T_ELSE)
Does the code not allow an else to it?
<?php
$pirep = PIREPData::getRecentReportsByCount(1);
foreach($pirep as $p) {
echo '
'.$p->depicao.' <img src="/lib/skins/vdelta3/img/airplaneicon.png" alt=""> '.$p->arricao.'
FLIGHT: '.$p->code . $p->flightnum.'
AIRCRAFT: '.$p->aircraft.'
SUBMITTED: '.date(DATE_FORMAT, $p->submitdate).'
';
}
else
{
echo 'THERE IS NO FLIGHTS';
}
?>
web541
July 31, 2016, 8:55pm
5
No worries, feel free to use my code on your side, I purely gave it to you as an example
As per your issue above, this should solve the error
<?php
$pirep = PIREPData::getRecentReportsByCount(1);
if(!$pirep) {
echo 'THERE IS NO FLIGHTS';
} else {
foreach($pirep as $p) {
echo '
'.$p->depicao.' <img src="/lib/skins/vdelta3/img/airplaneicon.png" alt=""> '.$p->arricao.'
FLIGHT: '.$p->code . $p->flightnum.'
AIRCRAFT: '.$p->aircraft.'
SUBMITTED: '.date(DATE_FORMAT, $p->submitdate).'
';
}
}
?>
1 Like
Ariel
July 31, 2016, 11:43pm
6
No worries, feel free to use my code on your side, I purely gave it to you as an example
As per your issue above, this should solve the error
<?php
$pirep = PIREPData::getRecentReportsByCount(1);
if(!$pirep) {
echo 'THERE IS NO FLIGHTS';
} else {
foreach($pirep as $p) {
echo '
'.$p->depicao.' '.$p->arricao.'
FLIGHT: '.$p->code . $p->flightnum.'
AIRCRAFT: '.$p->aircraft.'
SUBMITTED: '.date(DATE_FORMAT, $p->submitdate).'
';
}
}
?>
web541,
Worked like a charm. Thank you againā¦i really appreciate it!!
1 Like
Just out of curiosity, what will the html code be?