Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it's time to take a step back and look at what you're doing :) This function should do what you want (even if you fixed the infinite loop problem in the function you gave, I don't think it would act how you want it to.):</p> <pre><code>function getBlogMenu(){ $dbhost = 'localhost'; $dbuser = ' '; $dbpass = ' '; $con = mysql_connect($dbhost, $dbuser, $dbpass); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ado_ocblog", $con); $htmlString = ""; $result = mysql_query( "SELECT * FROM subCat JOIN headCat ON subCat.headid = headCat.id ORDER BY headid ASC;"); // arrays can have strings as keys as well as numbers, // and setting $some_array[] = 'value'; (note the empty brackets []) // automatically appends 'value' to the end of $some_array, // so you don't have to keep track of or increment indexes while ($row = mysql_fetch_assoc($result)) { $test[$row["headc"]][] = $row["subc"]; } // don't close the connection until after we're done reading the rows mysql_close($con); // $test looks like: array('headc1' =&gt; array('subc1', 'subc2', 'sub3'), 'headc2' =&gt; array('subc4', 'subc5'), ...) // so we step through each headc, and within that loop, step through each headc's array of subc's. foreach($test as $headc =&gt; $subc_array) { $htmlString.= '&lt;h3&gt;&lt;a href=""&gt;'.$headc.'&lt;/a&gt;&lt;/h3&gt;&lt;div&gt;&lt;ul&gt;'; foreach($subc_array as $subc) { $htmlString.= '&lt;li&gt;&lt;a class="sub_menu" href="#"&gt;'.$subc.'&lt;/a&gt;&lt;/li&gt;'; } $htmlString.= '&lt;/ul&gt;&lt;/div&gt;'; } return $htmlString; } </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.
    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