Jump to content


Adding the total of one column

  • Please log in to reply
3 replies to this topic

#1 vollmey

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 May 2006 - 03:11 AM

I really hate to ask I basic question to alot of you guys, but I just can't figure it out. On my website [a href=\"http://www.davevollmer.com\" target=\"_blank\"]www.davevollmer.com[/a] I would like to add the Block Time column and display the figure as "Total Time" in a box centered right above the table.

Here is what I have now

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
// Execute SQL query
$query = "SELECT IDPIREP, CreatedOn, IDPilot, PilotName, Airline, FlightNumber, OriginAirport, DestinationAirport, BlockTime, DistanceFlight, FlightFuel FROM pirep ORDER BY CreatedON DESC";
$result = mysql_query($query) or die("SQL query failed.");

if (mysql_num_rows($result) == 0) die("There are currently no PIREPs available.");



<meta http-equiv="Content-Language" content="en-us">
<title>FS Flight Keeper - Dave Vollmer.com Flights</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Expires" content="0">
<style type="text/css">
tr {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;

<font size="3" face="Verdana, Arial, Helvetica, sans-serif"><strong>Davevollmer.com Flights</strong></font>
<table width="680" border="0" cellpadding="4" cellspacing="0" bordercolor="#FFFFFF">
<tr bordercolor="#FFFFFF" bgcolor="#00CCFF">
<td width="80"><font color="#333333"><strong>Filed On</strong></font></td>
<td width="110"><font color="#333333"><strong>Flight</strong></font></td>
<td width="180"><font color="#333333"><strong>Pilot</strong></font></td>
<td width="352"><font color="#333333"><strong>From - To </strong></font></td>
<td width="55"><div align="center"><font color="#333333"><strong>Block Time</strong></font></div></td>
<td width="111"><div align="center"><font color="#333333"><strong>Distance NM</strong></font></div></td>
<td width="80"><div align="center"><font color="#333333"><strong>Flight Fuel (lbs) </strong></font></div></td>
$i = 0;
while ($row = mysql_fetch_object($result)) { ?>

<?php if (fmod($i, 2) == 0) {
print "<tr bordercolor=\"#FFFFFF\" bgcolor=\"#FFFFCC\">";
else {
print "<tr bordercolor=\"#FFFFFF\" bgcolor=\"#FFCC99\">";
<td><?php print date("m.d.Y", convert_timestamp($row->CreatedOn)); ?></td>
<td><a href="PIREPDetails.php?ID=<?php print $row->IDPIREP; ?>" target="PIREP_DETAILS"><?php print $row->Airline." ".$row->FlightNumber; ?></a></td>
<td><?php print $row->PilotName." (".$row->IDPilot.")"; ?></td>
/* ### Changed v2.6 ### */
print $row->OriginAirport;
if (strlen($row->DestinationAirport) != 0) print "  <b>-></b>  ".$row->DestinationAirport;
</td> <td><div align="center"><?php print $row->BlockTime; ?></div></td>
<td><div align="center"><?php print $row->DistanceFlight; ?></div></td>
<td><div align="center"><?php print number_format($row->FlightFuel, 0, ",", "."); ?></div></td>
$i = $i + 1;


It's proably very, very, very basic but any help would be greatly appreciated.


Dave Vollmer

#2 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 08 May 2006 - 03:52 AM

What field type is the Blocktime field? And what kind of data does it hold? If it where just numbers it would be a simple...
SELECT SUM(Blocktime) AS totaltime FROM tbl;
But it sounds to me like you have some sort of timestamp in this field.

#3 vollmey

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 May 2006 - 11:54 AM

Ok, once again I'm going to show my Newb status. Type of field = Varchar and yes it just hold numbers.

#4 trq

  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 08 May 2006 - 02:45 PM

Well, VARCHAR is of absolutley no use here. You cant sum up strings. If you can, change the field to some sort of numeric type eg INT. Then you can simply follow my example above.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users