#1
  1. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,535
    Rep Power
    112

    Month-ify an array


    Well, for only a single page, atm, tables are to be built in a multiple, per-month, action. The returned result from the database is the result set for a requested year.

    I think this just needs 2 parts. 1.) A check/trigger of some kind that it is this sort of array vs any other to initiate TRUE in perhaps an if/else. 2.) A loop to rebuild itself, making the outer-most index numerically defined via month from the 2nd/'date' index.

    The else may simply be omitted since in any other case, a foreach() to build the tables will use the same data, and just loop once.

    I feel this will be a quick simple thing, but am probably just putting too much thought into the idea... ^_^
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  2. #2
  3. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,815
    Rep Power
    9646
  4. #3
  5. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,535
    Rep Power
    112
    It will start as a basic result set like the upper example, and I need to group it by month, such as the lower example, with the numerical index matching the included month.
    PHP Code:
    array(
        [
    0] => array(title01/01/2018something, else),
        [
    1] => array(title01/03/2018something, else),
        [
    2] => array(title05/01/2018something, else),
        [
    3] => array(title06/08/2018something, else),
        [
    4] => array(title06/23/2018something, else)
    )
    array(
        [
    1] => array(
            [
    0] => array(title01/01/2018something, else),
            [
    1] => array(title01/03/2018something, else)
        ),
        [
    5] => array(
            [
    0] => array(title05/01/2018something, else)
        ),
        [
    6] => array(
            [
    0] => array(title06/08/2018something, else),
            [
    1] => array(title06/23/2018something, else)
        )

    Last edited by Triple_Nothing; January 6th, 2018 at 05:06 PM.
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  6. #4
  7. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,815
    Rep Power
    9646
    Then foreach + lookup array based on the month number.
    Code:
    result = []
    foreach (array as key => value) {
      m = the month number
      if (!isset(result[m])) result[m] = []
      result[m][] = value
    }
    Same basic structure as for all "group by"-type operations: start with an empty array, loop, derive the appropriate key from each value, check that the final array has that key or else add it with an empty array, then append to that array.
  8. #5
  9. No Profile Picture
    Super Moderator
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,535
    Rep Power
    112
    Yep. Figured I was over-thinking it. Thank you very much!
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.

IMN logo majestic logo threadwatch logo seochat tools logo