Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursive tree traversal with PHP - layout issue
    primarykey
    data
    text
    <p>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:</p> <pre><code>id description parentId 1 Level 1 0 2 Level 2 0 3 Level 1a 1 4 Level 1b 1 5 Level 1a1 3 </code></pre> <p>and the code I'm using right now is this:</p> <pre><code>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 '&lt;div class="tabs"&gt;'; echo '&lt;span class="level1"&gt;'.$row['description'].'&lt;/span&gt;'; echo '&lt;ul id="main-nav"&gt;&lt;h2 align="center"&gt;Categories&lt;/h2&gt;&lt;/ul&gt;'; echo '&lt;div&gt;'.$row['id'].'&amp;nbsp;'.$row['description'].'&amp;nbsp;'.$row['parentId'].'&lt;/div&gt;'; if ($row['parentId'] == 1) { } echo '&lt;/div&gt;'; } else { echo '&lt;div&gt;'.$row['id'].'&amp;nbsp;'.$row['description'].'&amp;nbsp;'.$row['parentId'].'&lt;/div&gt;'; } printChildQuestions($row['id']); } } printChildQuestions(0); </code></pre> <p>and the html that needs to be generated for is here: <a href="http://jsfiddle.net/Cyb2N/" rel="nofollow">http://jsfiddle.net/Cyb2N/</a></p> <p>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!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload