Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    inserting a total of a column in a table

    I have a database which feeds into a table on my webpage. I am trying to add a total for each column which has a number vavlue. I have been struggling wtih this for hours and just can't figure it out. The code I am struggling with is at line 52-54.

    Obviously the name fields won't be totaled, but all the rest should be.

    Thanks ahead of time.

    Mike



    PHP Code:

    <?php require_once('../Connections/ReunionPreRegDB.php'); ?>
    <?php
    mysql_select_db
    ($database_ReunionPreRegDB$ReunionPreRegDB);
    $query_PreRegRosterrecordset "SELECT GradYear, LName, FName, FriSocial, SatRHSTour, SatPicnic, SatDance, SunGolf, SunBrunch, SunOtherEvent, HotelRooms FROM PreRegDB ORDER BY GradYear ASC";
    $PreRegRosterrecordset mysql_query($query_PreRegRosterrecordset$ReunionPreRegDB) or die(mysql_error());
    $row_PreRegRosterrecordset mysql_fetch_assoc($PreRegRosterrecordset);
    $totalRows_PreRegRosterrecordset mysql_num_rows($PreRegRosterrecordset);
    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>

    <body>



    <table border="1" cellpadding="1" cellspacing="1">
      <tr>
        <td><div align="center">Graduation<br />
        Year</div></td>
        <td><div align="center">Last<br />
        Name</div></td>
        <td><div align="center">First<br />
        Name</div></td>
        <td><div align="center">Friday<br />
          Evening<br />
        Social</div></td>
        <td><div align="center">Saturday<br />
          RHS<br />
        Tour</div></td>
        <td><div align="center">Saturday<br />
        Picnic</div></td>
        <td><div align="center">Saturday<br />
          Dinner/<br />
        Dance</div></td>
        <td><div align="center">Sunday<br />
        Golf</div></td>
        <td><div align="center">Sunday<br />
        Brunch</div></td>
        <td><div align="center">Sunday<br />
          Other<br />
        Event</div></td>
        <td><div align="center">Hotel<br />
        Rooms</div></td>
      </tr>
      <tr>
        <td colspan="3"><div align="right">Event Totals</div></td>
        <td>
        
        <?php 
    $total 
    += $FriSocial;
     
    ?>

        
        
        
        </td>
            
        
            
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <?php do { ?>
        <tr>
          <td><?php echo $row_PreRegRosterrecordset['GradYear']; ?></td>
          <td><?php echo $row_PreRegRosterrecordset['LName']; ?></td>
          <td><?php echo $row_PreRegRosterrecordset['FName']; ?></td>
          <td><div align="center"><?php echo $row_PreRegRosterrecordset['FriSocial']; ?></div></td>
          <td><div align="center"><?php echo $row_PreRegRosterrecordset['SatRHSTour']; ?></div></td>
          <td><div align="center"><?php echo $row_PreRegRosterrecordset['SatPicnic']; ?></div></td>
          <td><div align="center"><?php echo $row_PreRegRosterrecordset['SatDance']; ?></div></td>
          <td><div align="center"><?php echo $row_PreRegRosterrecordset['SunGolf']; ?></div></td>
          <td><div align="center"><?php echo $row_PreRegRosterrecordset['SunBrunch']; ?></div></td>
          <td><div align="center"><?php echo $row_PreRegRosterrecordset['SunOtherEvent']; ?></div></td>
          <td><div align="center"><?php echo $row_PreRegRosterrecordset['HotelRooms']; ?></div></td>
        </tr>
        <?php } while ($row_PreRegRosterrecordset mysql_fetch_assoc($PreRegRosterrecordset)); ?>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result
    ($PreRegRosterrecordset);
    ?>

  • #2
    New to the CF scene
    Join Date
    Feb 2010
    Location
    Texas
    Posts
    8
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Try another query at the end with the SUM() function:
    PHP Code:
    $totals_sql "SELECT SUM(HotelRooms) AS total_HotelRooms,SUM(SunGolf) AS total_SunGolf FROM PreRegDB ORDER BY GradYear ASC";
    $totals_result mysql_query($totals_sql$ReunionPreRegDB) or die(mysql_error());
    $totals_row mysql_fetch_assoc($totals_result);
    echo 
    'total_HotelRooms: ' $totals_row['total_HotelRooms'] . "<br>\n";
    echo 
    'total_SunGolf: ' $totals_row['total_SunGolf'] . "<br>\n"

  • Users who have thanked F00Baron for this post:

    mikeberish (02-28-2010)

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thankyou, thankyou, thankyou

    YOU ROCK!!

    With a few modifications I made it fit exactly what I needed. I very much appreciate your help. Wish I knew more about PHP and HTML.

    Do you have a recommendation for a way to learn this stuff?

    Thanks again,



    Mike

  • #4
    New Coder
    Join Date
    Feb 2010
    Location
    UK, North West
    Posts
    36
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Hello Mike,
    The best way to learn PHP in my opinion is by doing what you're doing now. Asking for help when you're stuck on forums, and of course by actualling coding with trial and error.

    Practice makes perfect,
    Shaun


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •