login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Hulp nodig

Offline Cash - 01/03/2005 10:57
Avatar van CashNieuw 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
  1. <?php
  2. /* Constants */
  3. @define ("MYSQL_CONNECT_INCLUDE", "connect_db.php"); // MySQL database connection (a sample file is included)
  4.  
  5.  
  6. /* Database connection */
  7. include(MYSQL_CONNECT_INCLUDE);
  8.  
  9. /* Select all pilots */
  10. $query = "SELECT * FROM pilots ORDER BY pilot_num ASC";
  11. $result = mysql_query($query);
  12.  
  13. /* Determine the number of pilots */
  14. $number = mysql_numrows($result);
  15.  
  16. if ($number > 0) {
  17. /* Print roster header
  18. Change this HTML to fit your webpage layout */
  19. print "<table>";
  20. print "<tr>";
  21. print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>NUMBER</b></font></td>";
  22. print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>NAME</b></font></td>";
  23. print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>CITY</b></font></td>";
  24. print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>COUNTRY</b></font></td>";
  25. print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>FLIGHT TIME</b></font></td>";
  26. print "<td bgcolor=#000080 width=73 height=12 align=left><font face=Arial color=#FFFFFF size=1><b>STATUS</b></font></td>";
  27. print "</tr>";
  28.  
  29. /* Get pilots info */
  30. for ($i=0; $i<$number; $i++) {
  31. $num = mysql_result($result,$i,"pilot_num");
  32. $name = mysql_result($result,$i, "name");
  33. $city = mysql_result($result,$i, "city");
  34. $country = mysql_result($result,$i, "country");
  35. $status = mysql_result($result,$i, "status");
  36. $id = mysql_result($result,$i, "pilot_id");
  37.  
  38. /* Calculate flight hours */
  39. $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";
  40. $result_hours = mysql_query($query_hours);
  41.  
  42. if (mysql_numrows($result_hours) > 0) {
  43. $time = mysql_result($result_hours,0,"duration_sum");
  44. }
  45.  
  46. /* Display roster entries */
  47. print "<tr>";
  48. print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$num</font></td>";
  49. print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$name</font></td>";
  50. print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$city</font></td>";
  51. print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$country</font></td>";
  52. print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$time</font></td>";
  53. print "<td width=73 height=12 align=left><font face=Arial size=1 color=#000080>$status</font></td>";
  54. print "</tr>";
  55. }
  56.  
  57. print "</table>";
  58. }
  59.  
  60.  
  61. /* Close the database connection */
  62. ?>


En hier een foto van de tabellen: http://69.93.178.213/tigers/databse.jpg

Enorm bedankt aan wie mij kan helpen!

1 antwoord

Gesponsorde links
Offline Thomas - 30/11/1999 00:00 (laatste wijziging 30/11/1999 00:00)
Avatar van Thomas Moderator Je kan de totaal gevlogen afstand en het totale brandstofverbruik [i]per piloot[i] in je flight hours query ($query_hours) opnemen.rnJe hebt volgens mij in die query de tabel pilots niet nodig (pilot_id komt ook voor in de tabel reports).rnrnJe zult dus enerzijds de query moeten aanpassen (weet niet zeker of dit werkt - voer hem eerst eens uit in phpMyAdmin)rn[code]SELECT sec_to_time(sum(time_to_sec(duration))) AS duration_sum,rnSUM(fuel) AS fuel_sum,rnSUM(distance) AS distance_sumrnFROM reportsrnWHERE pilot_id=$idrnGROUP BY pilot_id[code]rnrnen anderzijds je HTML-tabel met deze gegevens uitbreiden (kopje en inhoud).rnrnAls je een indeling per vlucht wilt maken zul je een nieuwe query (en een nieuw HTML-tabelletje) moeten maken denk ik.
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.179s