这是 PHP5 5.3.10 的自定义和数据库驱动的无序列表脚本 如您所见,此方法来自程序背景。
它大约 1 岁了,今天,我想再写一次,这个脚本的数据仅来自 1 个 SQL 表;由 dao 类和多个公共函数触发。
这段代码按预期工作,但对我来说有点难看,你怎么看,如果你想再写一次,你会从哪里开始?
基本上脚本会产生这个 html :
<div class="menuInside" id="menu">
<div>
<ul class="">
<li class="first"><a onclick="this.blur()" id="bienvenue" href="/bienvenue.html"><img width="109" height="19" alt="Bienvenue" src="/images/menu/bienvenue.png"></a></li>
<li class="text"><a href="/bienvenue.html">Nous sommes heureux de vous accueillir sur notre site Internet.</a></li>
</ul>
</div>
<div>
<ul class="insidemiddle ulactive">
<li class="second"><a onclick="this.blur()" id="marques" href="/lingerie-feminine.html"><img width="102" height="23" alt="Marques" src="/images/menu/marques.png"></a></li>
<li class="elements"><a href="/barbara.html">Barbara</a></li>
<li class="elements"><a href="/calida.html">Calida</a></li>
<li class="elements"><a href="/canat.html">Canat</a></li>
<li class="elements"><a href="/chantelle.html">Chantelle</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elements"><a href="/charmline-lidea.html">Charmline & Lidea</a></li>
<li class="elements"><a href="/eminence.html">Eminence</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elements"><a href="/empreinte.html">Empreinte</a></li>
<li class="elementsOne"><a href="/lisanza.html">Lisanza</a></li>
<li class="elements"><a href="/lise-charmel.html">Lise Charmel</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elements"><a href="/lou.html">Lou</a></li>
<li class="elementsThree"><a href="/marjolaine.html">Marjolaine</a></li>
<li class="elements"><a href="/pain-de-sucre.html">Pain de Sucre</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elements"><a href="/rcrescentini.html">R. Crescentini</a></li>
<li class="elements"><a class="active" href="/save-the-queen.html">Save The Queen</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elements"><a href="/secret-eva.html">Secret d'Eva</a></li>
<li class="elements"><a href="/trasparenze.html">Trasparenze</a></li>
<li class="elements"><a href="/triumph.html">Triumph</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elements"><a href="/twin-set.html">Twin Set</a></li>
</ul>
</div>
<div>
<ul class="insidemiddle">
<li class="first"><a onclick="this.blur()" id="lingerie" href="/lingerie-feminine.html"><img width="88" height="21" alt="Lingerie" src="/images/menu/lingerie.png"></a></li>
<li class="elementsOne"><a href="/lingerie-feminine.html">Féminin</a></li>
<li class="elements"><a href="/lingerie-masculine.html">Masculin</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elementsTwo"><a href="/lingerie-de-nuit.html">Linge de Nuit</a></li>
<li class="elements"><a href="/articles-balneaires.html">Articles Balnéaires</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elementsNine"><a href="/collants-bas-mi_bas-chaussettes.html">Collants, Bas, Mi-bas, Chaussettes...</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
<li class="elementsTen"><a href="/laine-et-soie.html">Laine et Soie</a><img width="9" height="9" class="last" alt="" src="/images/menu/menu_item.png"></li>
</ul>
</div>
<div>
<ul class="">
<li class="first"><a onclick="this.blur()" id="contact" href="/contact.html"><img width="106" height="19" alt="Contact" src="/images/menu/contact.png"></a></li>
<li class="text"><a href="/contact.html">Si vous souhaitez nous faire part de vos impressions ou pour tout autre commentaire...<br>
<br>
Nos horaires d'ouvertures</a></li>
</ul>
</div>
</div>
你想指出我正确的方向吗?
这是脚本:
<?php
$id=isset($_GET['id'])?$_GET['id']:1;
($id!=1)?$classNav='menuInside':$classNav='menu';
?>
<div id="menu" class="<?=$classNav?>"><?php $cliao=new cliao();
$ActiveNav_result=$cliao->SubNav(array(" display_block"=>'=1'," id_marque"=>'='.$id),"id_menu",1);
$ActiveNav_item=$cliao->fetchResult($ActiveNav_result);
$Nav_result=$cliao->Nav(array(" display_block"=>'=1'),"id_menu");
while($MainNav_items=$cliao->fetchResult($Nav_result)){$SubNav_result=$cliao->SubNav(array(" display_block"=>"=1"," id_menu"=>'='.$MainNav_items->id_menu),"id_menu",1);
if($classNav!="menu"){($MainNav_items->Nav_type==1)?$class='insidemiddle':$class='';
($ActiveNav_item->id_Nav==$MainNav_items->id_menu)?$class.=' ulactive':$class.='';
echo '<div><ul class="'. $class .'">'."\n";
}else{
($MainNav_items->Nav_type==1)?$class='ulactive middle':$class='ulactive';
echo '<div><ul class="'.$class.'">'."\n";
}
while($MainSubNav_items=$cliao->fetchResult($SubNav_result)){
($MainNav_items->class_block==2)?$firstclass='class="first"': $firstclass='class="second"';
echo ($MainNav_items->display_block==1)?'<li '.$firstclass.'><a href="'.$MainNav_items->href_link.'" id="'.$MainNav_items->name.'" onclick="this.blur()"><img src="/images/menu/'.$MainNav_items->name.'.png" alt="'.ucfirst($MainNav_items->name).'" width="'.$MainNav_items->image_width.'" height="'.$MainNav_items->image_height.'" /></a></li>'."\n":'';
}
$SubNav_result=$cliao->SubNav(array(" display_block"=>"=1"," id_menu"=>'='.$MainNav_items->id_Nav),"id_menu");
while($MainSubNav_items=$cliao->fetchResult($SubNav_result)){($MainSubNav_items->Nav_last=="yes")?$last='<img src="/images/menu/menu_item.png" alt="" width="9" height="9" class="last" />':$last='';
($MainSubNav_items->id_marque==$id)?$activeclass='class="active"':$activeclass='';
?>
<li class="<?=$MainSubNav_items->Nav_class?>"><a href="<?=$MainSubNav_items->href_link?>" <?=$activeclass?>><?=$MainSubNav_items->text?></a><?=$last?></li><?="\n"?><?php }echo '</ul></div>'."\n";
}
?>
</div>