www.webdeveloper.com
Results 1 to 3 of 3

Thread: Begginner Php project, need some help.

  1. #1
    Join Date
    Apr 2014
    Posts
    14

    Begginner Php project, need some help.

    I'm really trying to figure out how to go about doing what I want to do for my dashboard program. I'm a young java developer(In school) and I'm familliar with using MySQL for basics (Reading/Writing Data) however I'm not really sure how to go about doing this. For my project I'm trying to create a dashboard that can show me some statistics; So i guess here's what I need.

    • A script that will update a database with the (Date, int) <-- I know how to do this


    What I don't know how to do is the following:

    • Display information pertaining to a certain month (With a sum of all the ints)
    • Display information pertaining to certain days.



    Examples would be greatly appreciated as I can't find what I'm looking for on google.

  2. #2
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    Since you are storing dates as integers you can make use of time(), mktime(), gmmktime functions to build ranges for grouping data.
    PHP Code:
    list($month$day$year) = explode(' 'gmdate('n j Y'));
    // build a range for month (current month)
    $month_range = array(
        
    gmmktime(000$month1$year), // start, i.e. 1/1
        
    gmmktime(000$month+11$year), // end, i.e. 2/1
    );
    $day_range = array(
        
    // you can call mktime/gmmktime without some arguments,
        // those get auto-filled based on the current time.
        
    gmmktime(000), // today 0th hour (e.g. 12 am)
        
    gmmktime(2400), // tomorrow 0th hour
    ); 
    Last edited by ShrineDesigns; 05-25-2014 at 05:24 AM.

  3. #3
    Join Date
    May 2014
    Posts
    842
    Can you define what 'ints' is? I'm assuming you mean some form of integer, but what does that integer MEAN?

    What's your table structure? What existing queries are you using?

    You really aren't providing big enough a picture to tell you anything meaningful... but assuming 'date' is type DATE... Well, I'm going to call it tDate since you shouldn't use field names identical to a SQL type. (reserved words much?)

    to grab a sum of your 'int' field

    SELECT SUM(int) FROM testTable
    WHERE MONTH(tdate) == :month
    AND YEAR(tdate) == :year

    where you replace :month with the number/variable you want. You want to include YEAR since otherwise it would return ALL matching months from all years, something you likely DON'T want.

    Days isn't that hard either, just add DAY(fieldname):

    SELECT SUM(int) FROM testTable
    WHERE DAY(tdate) == :day
    AND MONTH(tdate) == :month
    AND YEAR(tdate) == :year
    Java is to JavaScript as Ham is to Hamburger.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles