473,760 Members | 8,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving a result to another table

I have a script that will print out the results of a table and make a
calculation of a total of one of the columns. See example:

<?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 take the result ($time) and save it to another
table, along with the name and id# of the pilot. I then want to call
from that table and print out the top 5 based upon flight times.

I have tried to store to a second table (tmp), by using code to this
script that appears after the $time calculation:

[code:1:4d5f0e55 d2]

$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:4d5f0e55 d2]

but this is not working.....get ting a parsing error and the data is
not stored in the new table.

Any ideas how to do this better?

Thanks

Jul 17 '05 #1
2 1955
maceo wrote:
I have a script that will print out the results of a table and make a
calculation of a total of one of the columns. See example:

[ big snip ]
What I want to do is take the result ($time) and save it to another
table, along with the name and id# of the pilot. I then want to call
from that table and print out the top 5 based upon flight times.

I have tried to store to a second table (tmp), by using code to this
script that appears after the $time calculation:

[code:1:4d5f0e55 d2]

$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:4d5f0e55 d2]

but this is not working.....get ting a parsing error and the data is
not stored in the new table.

Any ideas how to do this better?

Thanks

Based on the code you listed you are not executing your INSERT
statement.

HTH
Jerry
Jul 17 '05 #2
va*****@alltel-dot-net.no-spam.invalid (maceo) wrote:

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><fo nt face=Arial color=#FFFFFF
size=2><b>NUMB ER</b></font></td>";
print "<td bgcolor=#000080 width=120 height=12
align=left><fo nt face=Arial color=#FFFFFF
size=2><b>NA ME /
EMAIL</b></font></td>";
print "<td bgcolor=#000080 width=130 height=12
align=left><fo nt face=Arial color=#FFFFFF
size=2><b>CITY </b></font></td>";
print "<td bgcolor=#000080 width=93 height=12
align=left><fo nt face=Arial color=#FFFFFF
size=2><b>COUN TRY</b></font></td>";
print "<td bgcolor=#000080 width=93 height=12
align=left><fo nt face=Arial color=#FFFFFF
size=2><b>FLIG HT
TIME</b></font></td>";
print "<td bgcolor=#000080 width=75 height=12
align=left><fo nt face=Arial color=#FFFFFF
size=2><b><cen ter>STATUS</center></b></font></td>";
print "<td bgcolor=#000080 width=75 height=12
align=left><fo nt face=Arial color=#FFFFFF
size=2><b><cen ter>LOG
BOOK</b></center></font></td>";
print "</tr>";


Why do you hurt yourself with all of that repetitive coding? It is
certainly wastely, and is sure to lead to typographical errors and
cut-and-paste problem.

<style> <!--
table.one tr td {
background-color: #000080;
color: #ffffff;
font: bold 11pt arial,helvetica ,sans serif;
}
--> </style>

print "<td width=85>NUMBER </td>";
print "<td width=120>NAME / EMAIL</td>";
print "<td width=130>CITY</td>";

Isn't that easier to read? And it's SO much easier to maintain, such as
when you want to tweak the colors.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #3

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

Similar topics

4
2400
by: Jan Nordgreen | last post by:
The following code only generates the first csv file. The second request is just ignored. What am I doing wrong? I am using Mozilla Firefox, Windows XP, and Xampp. <?php require 'bm_connect.php'; // export to csv file the table bmbookmark and call it bookmarks.csv header("Content-type: text/csv");
7
3969
by: Gav | last post by:
If you had a class user with variables id, name, password. How would you save this object or its variable date to a MySQL database? And then if you had a dbase populated with id, name, password and you wanted to show a list of all of these how would you iterate through this and re populate the object variables? Are there any tutorials that you can recommend on this subject?
4
6724
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my code ?? thank you Pedro Leite From Portugal ------------------------------------
3
1933
by: corear | last post by:
I have a new case tracking system. The cases table has these fields: CaseID (Primary Key) StatusID (looked up in another table - Open, Pending, or Closed) Status Comment (memo field) Date&Time (when casse was opened) ProjectID (looked up in another table - various projects are listed there) CustomerID (looked up in another table - list of names and other info for each) Request (memo field) Result (memo field)
2
2226
by: jessDMiller | last post by:
I have no clue why the data from the form isn't saving into the database. What am I doing wrong? addAnnounce.php: <td align=top> <form action="index2.php" method="post">Heading:<br /><textarea name="heading" cols="50" rows="10"></textarea><br /><br />Announcement:<br /> <textarea name="announce" cols="50" rows="10"></textarea> <br /><br />Date:<br /><textarea name="date" cols="50" rows="10"></textarea><br /><br /><input...
2
4435
by: Prashantsd | last post by:
Hi, I just wanted to know if it is possible to save the form data into different table. The combox box list are from the different tables and want save in another new table. What are the settings I have to make inorder to save the data selected from combo box and result stored in text box in one table. Thanks Prash
9
1651
by: =?Utf-8?B?TWlrZTk5MDA=?= | last post by:
I save a number in the table and want to get that number again, but the number I get has lower precision than I expect. For example, when I divide 10/3 I get 3.3333333333333335 if the variable is of type Double. But saving this result into a table with a column of type Double decreases the precision to 3.333333333333333 , so when I get this number and multiply it 10 I do not get that exact number which is 10. How can I solve this...
3
1733
by: bluethunder | last post by:
Good morning guys, I have a problem regarding the usage of the command button in VB 6. I dont know what codes what i will gonna use. How will i gonna call the records from the table using command button and saving it from another table?
0
1581
by: ll | last post by:
I'm currently working with an ASP page that populates rows based on a query for course data by using a DO WHILE NOT EOF loop. An improvement I'm adding is a dropdown populated by query which shows each course number, so that the user can populate that course page with data from a previous course. My question is: once the data from the previous course is populating the current course page (after being selected from the aforementioned...
0
10107
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9945
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8768
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7324
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6599
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5214
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3863
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 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.