SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot BuyAnswersLinks's Avatar
    Join Date
    Aug 2008
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple array wont work for me

    I have the array below that isnt working for me correctly. It is simply suppose to get the amount from the first day of the month till today. When I run just the sql it works fine, and when I print the $firstdate it works fine. However, when I use the code below, it grabs ALL of the dates from all of the previous months.

    I am sure the error is something simple haha, but I dont know what is wrong. Any help is appreciated thanks in advance

    PHP Code:
    $sql_month mysql_query("SELECT SUM(value) FROM `monthly_billing` WHERE `date` >= '$firstdate'");
    $result_month mysql_fetch_array($sql_month);
    $month_total round($result_month[0], 2); 

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,412
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)
    What's the value of $firstdate?

  3. #3
    SitePoint Zealot BuyAnswersLinks's Avatar
    Join Date
    Aug 2008
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    What's the value of $firstdate?
    Hello, thank you for the help.

    The value is "2009-08-01"

    The code I am using is:

    PHP Code:
    // Details for Months
    $currentmonth date('m');
    $year date('Y');
    $todaysday date('d');
    $firstdate "$year-$currentmonth-01"
    You actually helped me fix the problem tho. I accidentally placed the code above after the array sql haha. I knew it was going to be something stupid. But you helped me fix it because when I copied the code I realized my mistakes so thank you

    I do have another question since we are on the topic, is there a better way to do the above array/date thingy? Thanks

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    date('Y-m-01')


Bookmarks

Posting Permissions

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