3-Level Nested Array in PHP & MYSQL -


i trying create nested array, in order produce nested list within webpage.

so far have managed following:

    array ( [2012] => array     (         [show 1] => array             (                 [0] => class 1             )          [show 2] => array             (                 [0] => class 1             )      )  [2009] => array     (         [show 1] => array             (                 [0] => class 1             )      )  [2008] => array     (         [show 1] => array             (                 [0] => class 1             )      )  ) 

however actual results have more 1 class per show, should like:

[2012] => array     (         [show 1] => array             (                 [0] => class 1                 [1] => class 2                 [2] => class 3             ) etc etc etc. 

i've managed far, haven't clue how continue, in order more 1 class per show.

my code follows:

$handlerresults = $db->query("select show_name, year, class_name vwhandlerresults handler_id = $gethandlerid order year desc"); $showname = ''; while($row = $handlerresults->fetch_array(mysqli_assoc)) { $year = $row['year']; $show = $row['show_name']; $results[$year][$show] = array($row['class_name']); } print_r($results); 

try changing

$results[$year][$show] = array($row['class_name']); 

to

$results[$year][$show][] = $row['class_name'] 

i think problem you're overwriting array each time pass through loop same 'show'. if said above, instead of overwriting, it'll put next class next available index.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -