セクションと質問で構成される配列を作成しました。セクションをループして、各セクションのネストされた質問を表示するにはどうすればよいですか。
これが私が配列を作成する方法です
$db = db_open();
$query = "SELECT * FROM assessment_selections WHERE assessment_id = '".$annual_assessment["id"]."' AND selection = '1' ORDER BY timestamp ASC";
$result = db_query($db, $query);
$result = db_fetch_all($result);
if (!is_array)
$result = array();
foreach($result as $row) {
$section[$row['section_id']][$row['question_id']] = $row;
}
ここに配列があります
Array
(
[1] => Array // Section 1
(
[1] => Array // Question 1
(
[assessment_selection_id] => 70
[assessment_id] => 32
[section_id] => 1
[question_id] => 1
[selection] => 1
[timestamp] => 1368172762
)
)
[2] => Array // Section 2
(
[3] => Array // Question 3
(
[assessment_selection_id] => 68
[assessment_id] => 32
[section_id] => 2
[question_id] => 3
[selection] => 1
[timestamp] => 1368166250
)
)
[3] => Array // Section 3
(
[4] => Array // Question 4
(
[assessment_selection_id] => 69
[assessment_id] => 32
[section_id] => 3
[question_id] => 4
[selection] => 1
[timestamp] => 1368172690
)
)
[4] => Array // Section 4
(
[5] => Array // Question 5
(
[assessment_selection_id] => 71
[assessment_id] => 32
[section_id] => 4
[question_id] => 5
[selection] => 1
[timestamp] => 1368174153
)
)
)
期待される結果(PHPでエコーアウトできるようにしたい方法)
セクション 1
- 質問1
- 質問 4
- 質問7
第2節
- 質問2
- 質問9
セクション 3
- 質問 3