我将继续展示当前 HTML 输出的外观,下面的同一个小提琴是我希望输出 HTML 的方式:http: //jsfiddle.net/xQ95X/3/
一切都很好,我只需要这个 jQuery 插件 ( Superfish ) 的 HTML 结构即可运行。该下拉菜单不适用于 LI 之外的子 UL。它们必须嵌套在里面。
阻止我以这种方式格式化 HTML 的部分如下:
<ul class="sf-menu">
<li><a href="#">HOME</a></li>
<?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<=$nrows;$i++) {
$row = mysql_fetch_array($result);
extract($row);
$sections[] = $section;
$sectionids[] = $sectionid;
if ($section == "FORUM") {
echo"<li><a href='#' rel='dropmenu$i'>$section</a></li>";
} else {
echo"<li><a href='#h' rel='dropmenu$i'>$section</a></li>";
}
}
// Submenu Items
for($s=0;$s<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 > 0) {
echo"<ul>";
for($t=0;$t<$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"<li><a href='" . dirname($_SERVER['PHP_SELF']) . "$sec/$catID-$title20/1.html'>$title</a></li>";
}
else {
echo"<li><a href='" . dirname($_SERVER['PHP_SELF']) . "$sec/photos/$catID-$title20/1.html'>$title</li></a>";
}
} elseif ($type=="Contact") {
$title20 = strtolower($title);
$title20 = str_replace(" ", "_", $title20);
echo "<li><a href='" . dirname($_SERVER['PHP_SELF']) . "contactus/contact_$title20.html'>$title</a></li>";
} elseif ($type=='Quote') {
$sql4="SELECT articleID FROM article WHERE category='49' AND Now() > 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 "<li><a href='" . dirname($_SERVER['PHP_SELF']) . "everton_quotes.php?id=$articleID'>$title</a></li>";
}
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() > 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 > 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 "<li><a href='" . dirname($_SERVER['PHP_SELF']) . "match/$year/$matchID2-$teams2/" . strtolower($venue) . "/matchreport.html'>$title</a></li>";
}
} 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 > 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 > 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 "<li><a href='" . dirname($_SERVER['PHP_SELF']) . "match/$year/$matchID3-$teams2/" . strtolower($venue) . "/teamnews.html'>$title</a></li>";
}
} else {
// Overides for missing pages
if($title == "Gwladys Street Preacher") {
echo"<li><a href='/fans/121-gwladys_street_preacher/index.html'>$title</a></li>";
}
elseif($title == "The Secret Fan") {
echo"<li><a href='/news/124-secret-fan/index.html'>$title</a></li>";
}
elseif($title == "Toffee Girl") {
echo"<li><a href='/fans/125-toffee_girl/index.html'>$title</a></li>";
}
else {
echo"<li><a href='" . dirname($_SERVER['PHP_SELF']) . $link . "'>$title</a></li>";
}
}
}
echo"</ul>";
}
}
echo "</ul>";
?>
我希望我提供了足够的信息,如果您需要其他信息,请告诉我。虽然 JSFiddle 应该让您很好地了解我希望如何输出 HTML。
PS - 我完全知道这不是最干净的代码,我的猜测是它需要大量的重新排列才能获得所需的输出。我愿意接受建议。