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 10 of 10
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts

    pull values by date in column!

    Hi,

    Quick question, but i have tried other code but it doesnt work.
    I want to do this:

    I have a table with amounts in cash and points. I want to total them all up and return values for each individual day, up to the last 5 days including today. How do i do that?

    Please help me!
    thanks.

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    do you have a date column in your database?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    maybe something like

    PHP Code:

    $start 
    mktime(000date("m"), date("d")-5,   date("Y"));
    $finish mktime(000date("m"), date("d"),   date("Y"));
    $query("SELECT data FROM tbl WHERE date BETWEEN ".$start." AND ".$finish ." "
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #4
    New Coder
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes, I have a date column called "date" as a unix time stamp.
    Here's what I have for example:
    User Id | cash | points | date
    1 0.10. 1. Time
    1. 0.50. 3. Time here
    3. 0.5. 3. Time

    Basically I just need to sum up the total of the cash and points, and then sort it by each day for the past 5 days.
    So here, user 1 should have 0.6 as total for cash and 4 total for points.
    How would I use SQL to return those values?

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    the code in post 3

    pull values by date in column!
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #6
    New Coder
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I need it to return a value for each separate day though. any idea?
    Would i need 5 seperate queries for each day?
    Last edited by prizegrand; 03-06-2013 at 04:29 PM.

  • #7
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    no just some php to split them up,

    there are several ways, how do you want them displayed?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #8
    New Coder
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Just one value for each day.
    For example, i would want to total up monday and return a value, tuesday and return a value, and so on, for the past 5 days.
    I'm making like a chart so each value would move the graph up and down.

    thanks so much for the help!

  • #9
    New Coder
    Join Date
    Dec 2011
    Posts
    34
    Thanks
    2
    Thanked 0 Times in 0 Posts
    bump... can anyone help me?

  • #10
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    709
    Thanks
    20
    Thanked 84 Times in 84 Posts
    something like:

    PHP Code:
    $start mktime(000date("m"), date("d")-5,   date("Y"));
    $finish mktime(000date("m"), date("d"),   date("Y"));
    $result $query("SELECT data FROM tbl WHERE date BETWEEN ".$start." AND ".$finish ." "

    while (
    $row mysql_fetch_array($result)) {
    $cash[$row['id']][$row['date']] = $cash[$row['id']][$row['date']] + $row['cash'];
    $points[$row['id']][$row['date']] = $points[$row['id']][$row['date']] + $row['points'];
    }
    foreach (
    $cash as $k1 => $v1) {
    foreach (
    $cash[$k1] as $k2 => $v2) {
    echo 
    'Date: '.$k2.' User ID '.$k1'cash - '.$v2.' points - '.$points[$k1][$k2];
    }

    Last edited by Arcticwarrio; 03-11-2013 at 12:20 AM.
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

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