I am creating a questionnaire for a client that requires the questions to be organized by 3 layers of levels, with a unknown amount of questions and categories. I've successfully created the U.I. and the code to pull the information from the database however I've been trying to find out how to get everything loading in the right place. The database is organized like so by the client so I have no control over it:
id description parentId
1 Level 1 0
2 Level 2 0
3 Level 1a 1
4 Level 1b 1
5 Level 1a1 3
and the code I'm using right now is this:
function printChildQuestions($parentid) {
$sql="SELECT * FROM pB_test WHERE parentID=$parentid";
$result=mysql_query($sql);
$i=0;
while (true) {
$row=mysql_fetch_array($result);
if (!$row) break;
if ($row['parentId'] == 0) {
echo '<div class="tabs">';
echo '<span class="level1">'.$row['description'].'</span>';
echo '<ul id="main-nav"><h2 align="center">Categories</h2></ul>';
echo '<div>'.$row['id'].' '.$row['description'].' '.$row['parentId'].'</div>';
if ($row['parentId'] == 1) {
}
echo '</div>';
} else {
echo '<div>'.$row['id'].' '.$row['description'].' '.$row['parentId'].'</div>';
}
printChildQuestions($row['id']);
}
}
printChildQuestions(0);
and the html that needs to be generated for is here: http://jsfiddle.net/Cyb2N/
The issue is every idea I've come up with needs me to hardcode the levels in and breaks when level 2 is introduced. Could someone shove me in the right direction? Thanks!