Help anyone?

Discussion in 'PHP' started by Marty Rogers, Nov 25, 2007.

  1. #1
    I have a field in my database called views and i'd like to output the total number of views that have been generated by calculating all of the views in the table together... Can anybody help me with a quick code to output this?

    Thanks in advance =].
     
    Marty Rogers, Nov 25, 2007 IP
  2. *louie*

    *louie* Peon

    Messages:
    48
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    select the field in the db, and using "while.." statement add the values then return the total.
     
    *louie*, Nov 25, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    No while() loop needed.

    
    SELECT SUM(views) AS total FROM table_name
    
    Code (sql):
     
    nico_swd, Nov 25, 2007 IP
  4. Marty Rogers

    Marty Rogers Guest

    Messages:
    596
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks alot mate.

    One more thing, i want to include a file in my site which resets my viewtoday field to 0, but only once after 12:01 of a new day.

    $query = "UPDATE table SET viewtoday=0 where active = 'yes'";

    Anybody know how i would do this? I've had the code before from somebody but i lost it.

    Thank you :)
     
    Marty Rogers, Nov 25, 2007 IP
  5. Marty Rogers

    Marty Rogers Guest

    Messages:
    596
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Okay nevermind, sorted it now - thanks again!

    :)
     
    Marty Rogers, Nov 25, 2007 IP
  6. Dadniel

    Dadniel Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Best way to do this is not a query in a web page - use cron jobs to run the query at whatever time you choose.

    D
     
    Dadniel, Nov 25, 2007 IP