php - Separate MySQL query results by month -


the situation

i have mysql database table many dates in it.

now need create table tableentries should this:

may        |          | 22.05.2014 | person 1 | person 2 23.05.2014 | person 1 | person 2  june       |          | 02.06.2014 | person 1 | person 2 25.06.2014 | person 1 | person 2 

etc..

the code

i trying create loop through query results so. , right there stuck.

i having this:

in "while" (fetch assoc) loop have this:

while ($row = $stmt->fetch(pdo::fetch_assoc)) {   $date = $row['pp_date'];   $month = date('m', strtotime($date));    $entryarray = array();  } 

you can see, first save month of date array. , don't know, how create array hold rows each month in array output result table.

i assume table report 1 year. if so, can use month index key on array.

$table = array(); while ($row = $stmt->fetch(pdo::fetch_assoc)) {   $month = date('m', strtotime($row['pp_date']));   if(!isset($table[$month]))   {      $table[$month] = array();   }    $table[$month][] = $row; //... add table row } 

you can echo $table array iterating on keys of array. grouped in order created. depends upon sql query.

foreach($table $month=>$rows) {      echo $month;      foreach($rows $row)      {         print_r($row);      } } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -