php - How to display the value of array as string or text not as index value -
i have 2 table 1 sections each section has many questions when echo got section text questions index value 0 1 2
<?php $result = mysql_query($query); if ($result) { $data = array(); while ($row = mysql_fetch_assoc($result)) { $data[($row['section_name'])][][($row['ques_text'])][] = array( 'section' => $row['section_name'], 'question' => $row['ques_text'] ); } foreach ($data $section => $questions) { echo '<h2>',htmlentities($section),'</h2>'; foreach ($questions $questions_text => $text) { echo '<h2>',($questions_text),'</h2>'; } } } ?>
you creating nested arrays , parens unneeded:
$data[$row['section_name']][][$row['ques_text']][] = array( 'section' => $row['section_name'], 'question' => $row['ques_text'] );
should be:
if (empty($data[$row['section_name']]) { $data[$row['section_name']] = array(); } $data[$row['section_name']][$row['ques_text']] = array( 'section' => $row['section_name'], 'question' => $row['ques_text'] );
also please see comments original question, no longer safe way use mysql php.
Comments
Post a Comment