Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulating Drop Down Menu from PHP/MYSQL Select Values. How to rearrange output
    text
    copied!<p>I'm going to go ahead and show how the current HTML output looks and in the same fiddle below is how I wish the HTML to be output: <a href="http://jsfiddle.net/xQ95X/3/" rel="nofollow">http://jsfiddle.net/xQ95X/3/</a></p> <p>Everything works great, I just need this HTML structure for the jQuery plugin (<a href="http://users.tpg.com.au/j_birch/plugins/superfish/" rel="nofollow">Superfish</a>) to be function. The dropdown won't work with the child UL's outside of the LI's. They must be nested inside.</p> <p>The part which is stopping me from formatting the HTML in this manner is below:</p> <pre><code> &lt;ul class="sf-menu"&gt; &lt;li&gt;&lt;a href="#"&gt;HOME&lt;/a&gt;&lt;/li&gt; &lt;?php $sql="SELECT * FROM section ORDER BY orderID"; $result=mysql_query($sql) or die ("Error!! BAD SELECT SEARCH STATEMENT"); $nrows = mysql_num_rows($result); // Top level Items for($i=1;$i&lt;=$nrows;$i++) { $row = mysql_fetch_array($result); extract($row); $sections[] = $section; $sectionids[] = $sectionid; if ($section == "FORUM") { echo"&lt;li&gt;&lt;a href='#' rel='dropmenu$i'&gt;$section&lt;/a&gt;&lt;/li&gt;"; } else { echo"&lt;li&gt;&lt;a href='#h' rel='dropmenu$i'&gt;$section&lt;/a&gt;&lt;/li&gt;"; } } // Submenu Items for($s=0;$s&lt;count($sections);$s++) { /*$sm1 = ($s - 1);*/ $sp1 = ($s + 1); $sql3="SELECT * FROM category WHERE sectionid='$sectionids[$s]'"; $result3=mysql_query($sql3) or die ("Error!! BAD SELECT SEARCH STATEMENT"); $nrows3 = mysql_num_rows($result3); if ($nrows3 &gt; 0) { echo"&lt;ul&gt;"; for($t=0;$t&lt;$nrows3;$t++) { $row3 = mysql_fetch_array($result3); extract($row3); if ($type=='Photo') { $title20 = strtolower($title); $title20 = str_replace(" ", "_", $title20); $sec = strtolower($sections[$s]); $sec = str_replace(" ", "_", $sec); if ($sec=='photos') { echo"&lt;li&gt;&lt;a href='" . dirname($_SERVER['PHP_SELF']) . "$sec/$catID-$title20/1.html'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } else { echo"&lt;li&gt;&lt;a href='" . dirname($_SERVER['PHP_SELF']) . "$sec/photos/$catID-$title20/1.html'&gt;$title&lt;/li&gt;&lt;/a&gt;"; } } elseif ($type=="Contact") { $title20 = strtolower($title); $title20 = str_replace(" ", "_", $title20); echo "&lt;li&gt;&lt;a href='" . dirname($_SERVER['PHP_SELF']) . "contactus/contact_$title20.html'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } elseif ($type=='Quote') { $sql4="SELECT articleID FROM article WHERE category='49' AND Now() &gt; publishingdate ORDER BY publishingdate DESC LIMIT 0, 1"; $result4=mysql_query($sql4) or die ("Error! bad select statement"); $row4=mysql_fetch_array($result4); extract($row4); echo "&lt;li&gt;&lt;a href='" . dirname($_SERVER['PHP_SELF']) . "everton_quotes.php?id=$articleID'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } elseif ($type=='LastMatch') { $sql4="select r.matchID as matchID2, r.venue, r.versus as versus2, s.year FROM regmatch r, season s WHERE r.season=s.seasonID AND Now() &gt; r.matchdate ORDER BY r.matchdate DESC LIMIT 0,1"; $result4=mysql_query($sql4) or die ("Error! bad select statement"); $nrows4=mysql_num_rows($result4); if ($nrows4 &gt; 0) { $row4=mysql_fetch_array($result4); extract($row4); if ($venue=='Home') { $teams = "Everton V $versus2"; $teams2 = "everton_vs_" . str_replace(" ", "_", strtolower($versus2)); } else { $teams = "$versus V Everton"; $teams2 = str_replace(" ", "_", strtolower($versus2)) . "_vs_everton"; } $year = str_replace("/", "-", $year); echo "&lt;li&gt;&lt;a href='" . dirname($_SERVER['PHP_SELF']) . "match/$year/$matchID2-$teams2/" . strtolower($venue) . "/matchreport.html'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } } elseif ($type=='NextMatch') { $sql5="select r.matchID as matchID3, r.venue, r.versus as versus2, s.year FROM regmatch r, season s WHERE r.season=s.seasonID AND r.matchdate &gt; Now() ORDER BY r.matchdate ASC LIMIT 0,1"; $result5=mysql_query($sql5) or die ("Error! bad select statement"); $nrows5=mysql_num_rows($result5); if ($nrows5 &gt; 0) { $row5=mysql_fetch_array($result5); extract($row5); if ($venue=='Home') { $teams = "Everton V $versus2"; $teams2 = "everton_vs_" . str_replace(" ", "_", strtolower($versus2)); } else { $teams = "$versus2 V Everton"; $teams2 = str_replace(" ", "_", strtolower($versus2)) . "_vs_everton"; } $year = str_replace("/", "-", $year); echo "&lt;li&gt;&lt;a href='" . dirname($_SERVER['PHP_SELF']) . "match/$year/$matchID3-$teams2/" . strtolower($venue) . "/teamnews.html'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } } else { // Overides for missing pages if($title == "Gwladys Street Preacher") { echo"&lt;li&gt;&lt;a href='/fans/121-gwladys_street_preacher/index.html'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } elseif($title == "The Secret Fan") { echo"&lt;li&gt;&lt;a href='/news/124-secret-fan/index.html'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } elseif($title == "Toffee Girl") { echo"&lt;li&gt;&lt;a href='/fans/125-toffee_girl/index.html'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } else { echo"&lt;li&gt;&lt;a href='" . dirname($_SERVER['PHP_SELF']) . $link . "'&gt;$title&lt;/a&gt;&lt;/li&gt;"; } } } echo"&lt;/ul&gt;"; } } echo "&lt;/ul&gt;"; ?&gt; </code></pre> <p>I hope I have provided enough information, let me know if you require anything else. Though the JSFiddle should give you a good idea of how I would like the HTML to be output. </p> <p>PS - I'm fully aware this isn't the cleanest code around, my guess is that it will need a fair amount of rearranging to get the desired output. I'm open to suggestions.</p>
 

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