Nieuw lid |
|
Hallo,
Ik ben spijtig genoeg geen php expert.
Ik heb een php bestand dat uit een tabel vluchturen en nog wat info leest.
In die MySQL tabel wordt per vlucht ook de verbruikte fuel en afgelegde afstand bijgehouden, dit had ik graag ook laten zien in de php pagina, maar ik heb geen gedacht hoe ik dat doe.
Hieronder zie je de php code die ik nu heb
<?php
/* Constants */
@define ("MYSQL_CONNECT_INCLUDE", "connect_db.php"); // MySQL database connection (a sample file is included)
/* Database connection */
include(MYSQL_CONNECT_INCLUDE);
/* Select all pilots */
$query = "SELECT * FROM pilots ORDER BY pilot_num ASC";
$result = mysql_query($query);
/* Determine the number of pilots */
$number = mysql_numrows($result);
if ($number > 0) {
/* Print roster header
Change this HTML to fit your webpage layout */
print "<table>";
print "<tr>";
print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>NUMBER</b></font></td>";
print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>NAME</b></font></td>";
print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>CITY</b></font></td>";
print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>COUNTRY</b></font></td>";
print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>FLIGHT TIME</b></font></td>";
print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>STATUS</b></font></td>";
print "</tr>";
/* Get pilots info */
for ($i=0; $i<$number; $i++) {
$num = mysql_result($result,$i,"pilot_num");
$name = mysql_result($result,$i, "name");
$city = mysql_result($result,$i, "city");
$country = mysql_result($result,$i, "country");
$status = mysql_result($result,$i, "status");
$id = mysql_result($result,$i, "pilot_id");
/* Calculate flight hours */
$query_hours = "SELECT sec_to_time(sum(time_to_sec(t2.duration))) AS duration_sum FROM pilots t1, reports t2 WHERE t1.pilot_id=$id AND t1.pilot_id=t2.pilot_id";
$result_hours = mysql_query($query_hours);
if (mysql_numrows($result_hours) > 0) {
$time = mysql_result($result_hours,0,"duration_sum");
}
/* Display roster entries */
print "<tr>";
print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$num</font></td>";
print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$name</font></td>";
print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$city</font></td>";
print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$country</font></td>";
print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$time</font></td>";
print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$status</font></td>";
print "</tr>";
}
print "</table>";
}
/* Close the database connection */
mysql_close();
?>
<?php /* Constants */ @define ("MYSQL_CONNECT_INCLUDE", "connect_db.php"); // MySQL database connection (a sample file is included) /* Database connection */ include(MYSQL_CONNECT_INCLUDE); /* Select all pilots */ $query = "SELECT * FROM pilots ORDER BY pilot_num ASC"; /* Determine the number of pilots */ if ($number > 0) { /* Print roster header Change this HTML to fit your webpage layout */ print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>NUMBER</b></font></td>"; print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>NAME</b></font></td>"; print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>CITY</b></font></td>"; print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>COUNTRY</b></font></td>"; print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>FLIGHT TIME</b></font></td>"; print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>STATUS</b></font></td>"; /* Get pilots info */ for ($i=0; $i<$number; $i++) { /* Calculate flight hours */ $query_hours = "SELECT sec_to_time(sum(time_to_sec(t2.duration))) AS duration_sum FROM pilots t1, reports t2 WHERE t1.pilot_id=$id AND t1.pilot_id=t2.pilot_id"; } /* Display roster entries */ print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$num</font></td>"; print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$name</font></td>"; print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$city</font></td>"; print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$country</font></td>"; print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$time</font></td>"; print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$status</font></td>"; } } /* Close the database connection */ ?>
En hier een foto van de tabellen: http://69.93.178.213/tigers/databse.jpg
Enorm bedankt aan wie mij kan helpen!
|