I have some code that extracts the data from a table and performs a
calculation (total time) on one of the columns.
Here is the code:
<?php
/* Database connection */
include(MYSQL_C ONNECT_INCLUDE) ;
/* Select all pilots */
$query = "SELECT * FROM pilots ORDER BY pilot_num ASC";
$result = mysql_query($qu ery);
/* 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=85 height=12
align=left><fon t face=Arial color=#FFFFFF
size=2><b>NUMBE R</b></font></td>";
print "<td bgcolor=#000080 width=120 height=12
align=left><fon t face=Arial color=#FFFFFF
size=2><b>NAME /
EMAIL</b></font></td>";
print "<td bgcolor=#000080 width=130 height=12
align=left><fon t face=Arial color=#FFFFFF
size=2><b>CITY</b></font></td>";
print "<td bgcolor=#000080 width=93 height=12
align=left><fon t face=Arial color=#FFFFFF
size=2><b>COUNT RY</b></font></td>";
print "<td bgcolor=#000080 width=93 height=12
align=left><fon t face=Arial color=#FFFFFF
size=2><b>FLIGH T
TIME</b></font></td>";
print "<td bgcolor=#000080 width=75 height=12
align=left><fon t face=Arial color=#FFFFFF
size=2><b><cent er>STATUS</center></b></font></td>";
print "<td bgcolor=#000080 width=75 height=12
align=left><fon t face=Arial color=#FFFFFF
size=2><b><cent er>LOG
BOOK</b></center></font></td>";
print "</tr>";
/* Get pilots info */
for ($i=0; $i<$number; $i++) {
$num = mysql_result($r esult,$i,"pilot _num");
$name = mysql_result($r esult,$i, "name");
$city = mysql_result($r esult,$i, "city");
$country = mysql_result($r esult,$i,
"country");
$status = mysql_result($r esult,$i,
"status");
$id = mysql_result($r esult,$i, "pilot_id") ;
$email = mysql_result($r esult,$i, "email");
$log = mysql_result($r esult,$i, "log");
/* 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($qu ery_hours);
if (mysql_numrows( $result_hours) > 0) {
$time =
mysql_result($r esult_hours,0," duration_sum");
}
?>
<table border="1">
<tr>
<td bgcolor=#F0F8FF width=78 height=12
align=left><fon t face=Arial size=2 color=#000080>< ? echo
$num; ?></font></td>
<td bgcolor=#F0F8FF width=120 height=12
align=left><fon t face=Arial size=2 color=#000080>< a
href="mailto:<? echo $email; ?>"><? echo
$name; ?></a></font></td>
<td bgcolor=#F0F8FF width=130 height=12
align=left><fon t face=Arial size=2 color=#000080>< ? echo
$city; ?></font></td>
<td bgcolor=#F0F8FF width=93 height=12
align=left><fon t face=Arial size=2 color=#000080>< ? echo
$country; ?></font></td>
<td bgcolor=#F0F8FF width=93 height=12
align=left><fon t face=Arial size=2 color=#000080>< ? echo
$time; ?></font></td>
<td bgcolor=#F0F8FF width=73 height=12
align=left><fon t face=Arial size=2 color=#000080>< ? echo
$status; ?></font></td>
<td bgcolor=#F0F8FF width=73 height=12 align=left><fon t
face=Arial size=2 color=#000080>< center><a
href="<? echo $log;
?>">Flightlog </a></center></font></td>
</tr>
</table>
<?
}
print "</table>";
}
/* Close the database connection */
mysql_close();
?>
What I want to do is to take the value of the calculation:
$time = mysql_result($r esult_hours,0," duration_sum");
and store it in another table. I have written some code and inserted
into the script below this line to store the info into a seperate
table:
[code:1:d1d69b6a d4]
$sql = "INSERT INTO tmp (mxpid,time,nam e) VALUES
('$num','$time' ,'$name')";
$query = "SELECT * FROM tmp ORDER BY time DESC";
$result = mysql_query($qu ery);
$number = mysql_numrows($ result);
if ($number > 0) {
for ($i=0; $i<$number; $i++) {
$mxpid = mysql_result($r esult,$i,"mxpid ");
$name = mysql_result($r esult,$i, "name");
$totaltime = mysql_result($r esult,$i,
"time");
[/code:1:d1d69b6a d4]
I am getting a parsing error and the results are not stored.
What I want to do is save this information and call it back from the
table tmp to show the top 5 pilots based on flight hours.
Is there an easier way to do this?
Thanks 0 1602 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: d.p. |
last post by:
Hi all,
I'm using MS Access 2003.
Bare with me on this description....here's the situation: Imagine insurance,
and working out premiums for different insured properties. The rates for
calculating premiums are dependant on the country in which the client is in.
Therefore, we have a Country table, with its list of rates, a client table
and...
|
by: Kieran Benton |
last post by:
Hi,
I have quite a lot of metadata in a WinForms app that I'm currently storing
within a hashtable, which is fine as long as I know the unique ID of the
track (Im storing info on media files). Up until now I've been sending the
track info to a seperate server app using serialization/sockets which stores
the metadata in a mysql db so that I...
|
by: hendry.johan |
last post by:
Hi,
I'm currently developing an HR system which involves storing a lot of
configurations per module, such as payroll module, absence/shift
module, training module, etc. total: around 100 configuration items.
Configurations here, ranging from a simple key to value pair, a key to
multiple values, and a key to several records of a / multiple...
|
by: Larry Bates |
last post by:
I'm trying to get the results of binascii.crc32
to match the results of another utility that produces
32 bit unsigned CRCs. binascii.crc32 returns
results in the range of -2**31-1 and 2**21-1. Has
anyone ever worked out any "bit twiddling" code to
get a proper unsigned 32 bit result from binascii.crc32?
Output snip from test on three...
|
by: TORQUE |
last post by:
Hi,
I am having some trouble with recording a field on a form into my Table after formatting it to calculate several fields on the form.
If i just put the amount in the field and have it linked to the correct field in my Table, it will record it. But not the other
if I have the field Total several others first.
Where am I going wrong?
...
| |
by: John Welch |
last post by:
Hi all. I'm creating a FE/BE database that will be used by about 6 users. As
usual, I have several fields, such as "OrganizationTypeID" that will get
values (via combo boxes in forms) from separate lookup tables. I know the
'correct' way to do this, using a long integer as the field type. In this
case, however, I am considering doing it...
|
by: NoDBExperience |
last post by:
Hi guys,
Hope to gather some information and help from all you experts out there.
I have VERY limited experience with Micorosft Access...
I have a form that displays the age of a customer taken from another field, (DOB).
The problem here is, this information is not visible in the table??
I also have ANOTHER field for class Totals,...
|
by: colin |
last post by:
Hi,
Ive got a difference in results depending on wether I run my app
in the debugger, or run it seperatly (or with <ctrl-f5>)
the results in the debugger seem to be more correct, although
the app isnt finished and theres still a lot of things it gets wrong.
the processing is so complex its hard to determine where the difference can
be...
|
by: kcdoell |
last post by:
Hello:
I thought I was done with this one but a user who is testing my DB just pointed out a problem.
I used the following in the afterupdate event:
Private Sub Binding_Percentage_AfterUpdate()
'Updates the Total calculation in the control "SumGWP", Sum50GWP, "SUMNWP" and Sum50NWP
'on the quick reference table on the Forecast form.
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |