SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding up columns, then finding how many with certain amounts?

    I have a database table like this

    | id | pin | 1 | 2 | 3 |..........| 20 |


    In the id column is a auto_incrementing number, in the pin column is a pin number referring to particular people, then in the numbered columns is a number - either "0" or "1".

    I've done the php code to list all the rows in the database table into a web page - easy!

    But how do I now have a web page table in the same page, that will look like this?

    | Total Checks | "total number of checks" |
    -------------------------------------------
    | Total 20 | "total with 20" |
    | Total 18-19 | "total with 18-19" |
    | Total 0-18 | "total with 0-18" |

    Getting the Total Checks is easy because that will be
    PHP Code:
    <? echo $num ?>
    But what about the others?

    This is the code to display ALL the rows

    PHP Code:
     <table border="1">
    <tr>
    <th align="center"><font face="Arial">Number</font></th>
    <th align="center"><font face="Arial">P.R.F.  Date</font></th>
    <th align="center"><font face="Arial">Case No</font></th>
    <th align="center"><font face="Arial">Call Sign</font></th>
    <th align="center"><font face="Arial">Attendant</font></th>
    <th align="center"><font face="Arial">Percentage %</font></th>
    <th align="center"><font face="Arial">Checked By</font></th>
    <th align="center"><font face="Arial">Date Checked</font></th>
    </tr>

    <td align="center"><font face="Arial">

    <?
    $i
    =0;
    while (
    $i $num) {


    $prfdate=mysql_result($result,$i,"prfdate");
    $prfcase=mysql_result($result,$i,"prfcase");
    $callsign=mysql_result($result,$i,"callsign");
    $attendant=mysql_result($result,$i,"attendant");
    $checkedpin=mysql_result($result,$i,"checkedpin");
    $checkdate=mysql_result($result,$i,"checkdate");
    $one=mysql_result($result,$i,"1");
    $two=mysql_result($result,$i,"2");
    $three=mysql_result($result,$i,"3");
    $four=mysql_result($result,$i,"4");
    $five=mysql_result($result,$i,"5");
    $six=mysql_result($result,$i,"6");
    $seven=mysql_result($result,$i,"7");
    $eight=mysql_result($result,$i,"8");
    $nine=mysql_result($result,$i,"9");
    $ten=mysql_result($result,$i,"10");
    $eleven=mysql_result($result,$i,"11");
    $twelve=mysql_result($result,$i,"12");
    $thirteen=mysql_result($result,$i,"13");
    $fourteen=mysql_result($result,$i,"14");
    $fifteen=mysql_result($result,$i,"15");
    $sixteen=mysql_result($result,$i,"16");
    $seventeen=mysql_result($result,$i,"17");
    $eighteen=mysql_result($result,$i,"18");
    $nineteen=mysql_result($result,$i,"19");
    $twenty=mysql_result($result,$i,"20");


    ?></font>

    <tr>
    <td align="center"><font face="Arial"><? echo $i+1?></font></td>
    <td align="center"><font face="Arial"><? echo $prfdate?></font></td>
    <td align="center"><font face="Arial"><? echo $prfcase?></font></td>
    <td align="center"><font face="Arial"><? echo $callsign?></font></td>
    <td align="center"><font face="Arial"><? echo $attendant?></font></td>
    <td align="center"><font face="Arial"><? echo ($one+$two+$three+$four+$five+$six+$seven+$eight+$nine+$ten+$eleven+$twelve+$thirteen+$fourteen+$fifteen+$sixteen+$seventeen+$eighteen+$nineteen+$twenty)*5?></font></td>
    <td align="center"><font face="Arial"><? echo $checkedpin?></font></td>
    <td align="center"><font face="Arial"><? echo $checkdate?></font></td>
    </tr>

    <td align="center"><font face="Arial">

    <?
    $i
    ++;
    }
    ?>

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post an example of your table with say 3 rows. Then post an example of the output you want from that info.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, take a look at this

    test page

    and you'll see what i want I think.




    And this is my database table

    checkid prfdate prfcase callsign attendant checkedpin 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
    1 2006-04-16 1008 BR008 PA02452 PA13831 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1
    2 2006-04-17 0106 BR008 TW01014 PA13831 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    3 2006-04-16 0790 BR008 PA02452 PA13831 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 2006-04-28


    To get the percentages in the table - I just added them all up and multiplied by 5 as you can see in my php code in my initial posting.

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone? I'm really stuck with this now.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Your link shows me a login page?

    Anyhow, to get the number of 1's, 2's, etc, you might count the switches in the loop. Something like:

    PHP Code:
    if ($one$count_one++;
    if (
    $two$count_two++;
    //etc 

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right, sorry about the link.

    I'll have a look at what you suggest but not sure it's going to be what I want.

    What I really want is to see how times $one + $two + etc + $twenty = 20

    ...and how many times it's between 18-19

    ... and how many times it's <18

    Does that make sense?
    Last edited by Caduceus; May 1, 2006 at 13:27.

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2004
    Location
    Telford, UK.
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either this is not possible or no one knows how to do it huh?


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
  •