473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Storing the results of a calculation in another table

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_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=85 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>NUMBER</b></font></td>";
print "<td bgcolor=#000080 width=120 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>NAME /
EMAIL</b></font></td>";
print "<td bgcolor=#000080 width=130 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>CITY</b></font></td>";
print "<td bgcolor=#000080 width=93 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>COUNTRY</b></font></td>";
print "<td bgcolor=#000080 width=93 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b>FLIGHT
TIME</b></font></td>";
print "<td bgcolor=#000080 width=75 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b><center>STATUS</center></b></font></td>";
print "<td bgcolor=#000080 width=75 height=12
align=left><font face=Arial color=#FFFFFF
size=2><b><center>LOG
BOOK</b></center></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");
$email = mysql_result($result,$i, "email");
$log = mysql_result($result,$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($query_hours);

if (mysql_numrows($result_hours) > 0) {
$time =
mysql_result($result_hours,0,"duration_sum");
}
?>
<table border="1">
<tr>
<td bgcolor=#F0F8FF width=78 height=12
align=left><font face=Arial size=2 color=#000080><? echo
$num; ?></font></td>
<td bgcolor=#F0F8FF width=120 height=12
align=left><font 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><font face=Arial size=2 color=#000080><? echo
$city; ?></font></td>
<td bgcolor=#F0F8FF width=93 height=12
align=left><font face=Arial size=2 color=#000080><? echo
$country; ?></font></td>
<td bgcolor=#F0F8FF width=93 height=12
align=left><font face=Arial size=2 color=#000080><? echo
$time; ?></font></td>
<td bgcolor=#F0F8FF width=73 height=12
align=left><font face=Arial size=2 color=#000080><? echo
$status; ?></font></td>
<td bgcolor=#F0F8FF width=73 height=12 align=left><font
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($result_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:d1d69b6ad4]
$sql = "INSERT INTO tmp (mxpid,time,name) VALUES
('$num','$time','$name')";

$query = "SELECT * FROM tmp ORDER BY time DESC";
$result = mysql_query($query);
$number = mysql_numrows($result);

if ($number > 0) {
for ($i=0; $i<$number; $i++) {
$mxpid = mysql_result($result,$i,"mxpid");
$name = mysql_result($result,$i, "name");
$totaltime = mysql_result($result,$i,
"time");
[/code:1:d1d69b6ad4]

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

Jul 17 '05 #1
0 1594

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
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...
6
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...
2
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...
12
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....
8
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...
14
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...
8
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...
12
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...
5
kcdoell
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.