Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursive function causing webpage to go completely blank
    primarykey
    data
    text
    <p>I'm trying to print a menu with a recursive function. I used examples of code from these questions:</p> <p><a href="https://stackoverflow.com/questions/10782810/echo-menu-tree-with-recursive-function">Echo menu tree with recursive function</a></p> <p><a href="https://stackoverflow.com/questions/8503151/create-an-multidimensional-array-from-a-database-table">Create an multidimensional array from a database table</a> </p> <p>The code seems right to me and is syntactically correct, but I get a blank page as a result. There are no errors, but the HTML following this php isn't showing up either. Does anyone have any thoughts? </p> <pre><code>$connect = mysqli_connect($db_host,$db_user,$db_password,$db_database) or die ("Couldn't connect to server: ".mysqli_error()); $query = "SELECT * FROM categories"; $result = mysqli_query($connect,$query) or die ("Couldn't execute query: ".mysqli_error()); function menuPrint($categories, $parent = 'root', $level = 0) { $menuList = '&lt;ul&gt;'; foreach($categories as $index =&gt; $category) { if($category['Parent'] == $parent) { $menuList .= '&lt;li id="'.$category['ID'].'" class="tier'.$level.'"&gt;'.$category['Name']; $check = $this-&gt;menuPrint($categories, $category['ID'], $level+1); if($check != '&lt;ul&gt;&lt;/ul&gt;') $menuList .= $check; $menuList .= '&lt;/li&gt;'; } } return $menuList . '&lt;/ul&gt;'; } $catgories = array(); while ($row = mysqli_fetch_assoc($result)) { $categories[] = array( 'ID' =&gt; $row['categoryId'], 'Name' =&gt; $row['categoryName'], 'Parent' =&gt; $row['parentCategory'], 'Disabled' =&gt; $row['disabled'] ); } $menu = $this-&gt;menuPrint($categories); echo $menu; mysqli_close($connect); </code></pre>
    singulars
    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