eco the total?

Discussion in 'PHP' started by izlik, Dec 13, 2007.

  1. #1
    hello.

    i was wondering how a query for php / mysql would look like when i want to search trough all the rows in the collumn "views" on my table "users" in my database and add the numbers on every row together to a total and echo it out where i want it ?

    i hope someone can help me with this
    thanks in advance.
     
    izlik, Dec 13, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $query = mysql_query("SELECT SUM(views) AS total FROM table_name") OR die(mysql_error());
    $count = mysql_fetch_assoc($query);
    
    echo $count['total'];
    
    PHP:
     
    nico_swd, Dec 13, 2007 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    thanks a lot nico! :)
     
    izlik, Dec 13, 2007 IP