Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Add values of fields

  1. #1
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Add values of fields

    Hi Folks,

    I am trying to sum the values of numbers in various fields and would like that result to appear in the table.

    I would appreciate any reply in this regards

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    In a database table or an html table? Can you post your html code or a sample form?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    thanks for the prompt reply.

    I have a page that can be veiwed at http://www.gnjgf.co.za/rhresultstest.php

    the idea is to sum the numbers right of the word PAR and the result to be posted under the word OUT

    Similarly for the next nine values and thier result to appear under the word IN

    OUT +IN result is to appear under TOTAL

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Where are those values coming from, are they static? Can you post the code you are using currently to get those values?
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi ,

    I hope this helps

    PHP Code:
    <?php

    $connect 
    mysql_connect("localhost""e*****""*********") or

    die (
    "Hey loser, check your server connection.");

    mysql_select_db("e*****_Members");

    $query1="select * from courses";

    $result=mysql_query($query1) or die(mysql_error());

    ?>
    <!--------THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE------------->

    <table border=2 width="85%" bordercolor="#D3E2FE" bordercolorlight="#FFFFFF" bordercolordark="#AFBCDB" style="font-size:12px" cellspacing=0>

    <caption><b><font style="font-size:14px" color="#00008B" face="Arial">
    TOURNAMENT RESULTS</font><b><caption>

    <!---------------------------------------------------------------------------------------------------->
    <! THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED>
    <!---------------------------------------------------------------------------------------------------->

    <tr>
    <td colspan="22">&nbsp;</td>
    </tr>

    <tr>

    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">HOLE</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 1</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 2</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 3</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 4</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 5</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 6</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 7</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 8</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 9</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">OUT</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">10</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">11</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">12</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">13</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">14</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">15</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">16</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">17</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">18</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">IN</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">TOTAL</font></b></th>

    </tr>

    <tr>

    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">PAR</font></b></th>

    <?php

    while($row=mysql_fetch_array($result)){

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole1'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole2'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole3'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole4'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole5'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole6'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole7'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole8'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole9'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole99'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole10'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole11'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole12'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole13'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole14'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole15'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole16'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole17'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole18'];

    echo 
    '</td><td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
    echo 
    $row['parhole999'];

    echo 
    "</td></tr>";

    if(!isset(
    $counter[$firstNAsAString]))
    $counter[$firstNAsAString] = 0;
    else
    $counter[$firstNAsAString]++;
    $last_surname $row['surname'];

    $i++;
    echo
    '</td></tr>';

    }

    echo 
    "</table>";

    ?>
    Last edited by Rob (SA); 05-01-2010 at 04:47 PM.

  6. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Your table looked off a bit I think I fixed that and the values are totaled too. It may have a few errors my server is unconnectable so I can't test it.

    PHP Code:
    <?php

    $connect 
    mysql_connect("localhost""e*****""*********") or

    die (
    "Hey loser, check your server connection.");

    mysql_select_db("e*****_Members");

    $query1="select * from courses";

    $result=mysql_query($query1) or die(mysql_error());

    ?>
    <!--------THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE------------->

    <table border=2 width="85%" bordercolor="#D3E2FE" bordercolorlight="#FFFFFF" bordercolordark="#AFBCDB" style="font-size:12px" cellspacing=0>

    <caption><b><font style="font-size:14px" color="#00008B" face="Arial">
    TOURNAMENT RESULTS</font><b><caption>


    <!---------------------------------------------------------------------------------------------------->
    <! THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED>
    <!---------------------------------------------------------------------------------------------------->


    <tr>
    <td colspan="22">&nbsp;</td>
    </tr>


    <tr>

    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">HOLE</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 1</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 2</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 3</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 4</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 5</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 6</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 7</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 8</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial"> 9</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">OUT</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">10</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">11</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">12</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">13</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">14</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">15</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">16</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">17</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">18</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">IN</font></b></th>
    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">TOTAL</font></b></th>

    </tr>

    <tr>

    <th bgcolor="#D6D6D8"><b><font style="font-size:11px" color="#00008B" face="Arial">PAR</font></b></th>

    <?php
    $value 
    1;
    $total 0;
    $front9 0;
    $back9 0;
    while(
    $row=mysql_fetch_array($result)){
        
    ?>
        <tr>
         <?php
        
    while ($value 18 ) {
            
    ?>
            <td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
            <?php
            
    echo $row["parhole$value"];
            
    ?>
              </td>
              <?php
              
    if ($value 10 ) {
            
    $front9 $front9 $row["parhole$value"];
            
    $total $total $front9;
            } else {
            
    $back9 $back9 $row["parhole$value"];
            
    $total $total $back9;
            } 
            <?
    php
              
    if ($value == ) {
                  
    ?>
                <td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
                <?php
                
    echo $front9;
                
    ?>
                  </td>
                <?php
            
    }
        if (
    $value == 18) {
             
    ?>
                <td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
                <?php
                
    echo $back9;
                
    ?>
                  </td>
                <td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
                <?php
                
    echo total;
                
    ?>
                  </td>
            }    
        $value++;
        }
        ?>
        </tr>
    <?php
    if(!isset($counter[$firstNAsAString])) {
        
    $counter[$firstNAsAString] = 0;
    } else {
        
    $counter[$firstNAsAString]++;
        
    $last_surname $row['surname'];
        
    $i++;
    ?>
    </td></tr>
    <?php
    }
    ?> 
    </table>
    Corrections to my coding/thoughts welcome.

  7. #7
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    Thanks for your time.

    I have posted the changes - however i now get a totally blank screen.

    Let me take a look and see where it needs some work

  8. #8
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I have had a look but to no avail.

    Still a blank screen

  9. #9
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Missed a reopening tag try this one. The blank screen is caused by the error.

    PHP Code:
    <?php
    $value 
    1;
    $total 0;
    $front9 0;
    $back9 0;
    while(
    $row=mysql_fetch_array($result)){
        
    ?>
        <tr>
         <?php
        
    while ($value 19 ) {
            
    ?>
            <td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
            <?php
            
    echo $row["parhole$value"];
            
    ?>
              </td>
              <?php
              
    if ($value 10 ) {
            
    $front9 $front9 $row["parhole$value"];
            
    $total $total $front9;
            } else {
            
    $back9 $back9 $row["parhole$value"];
            
    $total $total $back9;
            } 
            <?
    php
              
    if ($value == ) {
                  
    ?>
                <td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
                <?php
                
    echo $front9;
                
    ?>
                  </td>
                <?php
            
    }
        if (
    $value == 18) {
             
    ?>
                <td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
                <?php
                
    echo $back9;
                
    ?>
                  </td>
                <td align="center" bgcolor="#D6D6D8"><font style="font-size:10px" color="#00008B" face="Arial">';
                <?php
                
    echo total;
                
    ?>
                  </td>
            <?php
            
    }    
        
    $value++;
        }
        
    ?>
        </tr>
    <?php
    if(!isset($counter[$firstNAsAString])) {
        
    $counter[$firstNAsAString] = 0;
    } else {
        
    $counter[$firstNAsAString]++;
        
    $last_surname $row['surname'];
        
    $i++;
    ?>
    </td></tr>
    <?php
    }
    ?> 
    </table>
    Corrections to my coding/thoughts welcome.

  10. #10
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    Thanks agian for taking a look.

    If I preview the file prior to publishing this is the result

    Last edited by Rob (SA); 05-02-2010 at 07:30 AM.

Bookmarks

Posting Permissions

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