Im trying to get a while loop working inside another while loop I have got it to work before but can't manage it again.
im trying to count the total records in the flights query and then in the hours record im trying to add the time. I have got all the queries working individually but when I put them together it don't work.
Here is my code what could I change to make it work?
<?php
error_reporting (E_ALL ^ E_DEPRECATED);
// get results from database
$result = mysql_query("SELECT * FROM `phpvms_pilots` WHERE `confirmed` = '1' AND `retired` = '0' ORDER BY pilotid ASC;")
or die(mysql_error());
$resulttotalflights = mysql_query("SELECT COUNT(*) AS total_flights FROM `phpvms_pireps` WHERE `pilotid` = '$pid';")
or die(mysql_error());
$resulttotalhours = mysql_query("SELECT SEC_TO_TIME( SUM(TIME_TO_SEC( `flighttime_stamp` ) ) ) AS total_hours FROM phpvms_pireps WHERE pilotid = '$pid'")
or die(mysqli_error());
echo "<table width='100%' border='0' cellpadding='0' align='center'>";
echo "<tr>
<th align='center'>Pilot ID</th>
<th align='center'>Name</th>
<th align='center'>Rank</th>
<th align='center'>Total Flights</th>
<th align='center'>Total Hours</th>
<th align='center'>Vatsim ID</th>
<tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
//$pid = 'RFR' . $row['pilotid'];
$pid = $row['pilotid'];
$first = $row['firstname'];
$last = $row['lastname'];
$vid = $row['vatsimid'];
$rank = $row['rank'];
while($row_flights = mysql_fetch_array( $resulttotalflights )) {$flights = $row_flights['total_flights'];}
while($row_hours = mysql_fetch_array( $resulttotalhours )) {$hours = $row_hours['total_hours'];}
// echo out the contents of each row into a table
echo "<tr>";
//echo '<td>' . $pid . '</td>';
echo '<td><a href="' . $vaptams_profile . $pid . '">' . 'RFR' . $pid . '</a></td>';
echo '<td>' . $first . ' ' . $last . '</td>';
echo '<td>' . $rank . '</td>';
echo '<td>' . $flights . '</td>';
echo '<td>' . $hours . '</td>';
echo '<td><a href="' . $vatawere . $vid . '">' . $vid . '</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
Thanks Scott