COUNT Array Values

Discussion in 'PHP' started by timallard, Aug 24, 2009.

  1. #1
    ok...

    I am not sure if this is the best way to go about doing it,...but I am working from someone elses code handed off to me.

    I have a loop giving me a count of items from a DB,
    It is giving me the top 10 records and their count.

    e.x

    Tim - 30
    Mike - 50
    Denise - 44

    How can I essentially, count, a count?

    e.x. $total = 30 + 50 + 44

    This is what I currently have:

    <?php while ($rowData= mysql_fetch_array($resultData)){
    echo number_format($rowData['count']);
    } ?>

    I tried: $total[0] = number_format($rowData['count']);
    echo $total outside the loop but no dice...

    Im stuck!

    Thanks for your help.
    -Tim
     
    timallard, Aug 24, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php 
    $total = 0;
    while ($rowData= mysql_fetch_array($resultData)){
      $total += $rowData['count'];
      echo number_format($rowData['count']);
    }
    
    echo number_format($total);
     ?>
    PHP:
     
    premiumscripts, Aug 24, 2009 IP
  3. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #3
    ugh i over think things. you are a life saver, thank you.
    I am learning so much!!
     
    timallard, Aug 24, 2009 IP