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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding colum data from select results

    First off... Thanks to those of you that helped yesterday. Appreciate it.

    How do I sumarize a fields contents from all records returned from a select statement... IN PHP?

    Exp.

    two records returned with a column called 'visits'...

    one record has 20 in the visits column and the other has 30

    HOW can I get PHP to add up THIS COLUMN in those two records? ??
    Fritz Jung
    co-founder
    the Witches' Voice
    www.witchvox.com

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, assuming that you use mysql, you could do the following:

    PHP Code:
    $total 0;
    while (
    $row mysql_fetch_assoc()) {
        
    $total += $row["visits"];

    Just have the $total variable outside your loop and each time you operate on one record, you add the new value.... this seems quite trivial to me that I'm under the impression that I misunderstood your problem... if you still have trouble achieving your goal, could you rephrase your question?


  •  

    Posting Permissions

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