Reputation: 29
I am trying to generate the bellow menu dynamically using php and mysql
<ul id="prod_nav" class="clearfix">
<!-- top --> <li class="active"><a href="05-Pink-02-Category-List.html" class="top_link"><span class="down">Clothes</span></a>
<ul>
<h1> Men </h1>
<li><a href="ProductsList.php">Shirt </a></li>
<li><a href="ProductsList.php">T-shirt </a></li>
<li><a href="ProductsList.php">Polo shirt </a></li>
<li><a href="ProductsList.php">Formal shoes </a></li>
<li><a href="ProductsList.php">Sport shoes </a></li>
<li><a href="ProductsList.php">Suit </a></li>
<li><a href="ProductsList.php">Underwear </a></li>
<li><a href="ProductsList.php">Socks </a></li>
<li><a href="ProductsList.php">Pants </a></li>
</ul>
<ul>
<h1> Women </h1>
<li><a href="ProductsList.php">Shirt </a></li>
<li><a href="ProductsList.php">T-shirt </a></li>
<li><a href="ProductsList.php">Polo shirt </a></li>
<li><a href="ProductsList.php">High heel shoes </a></li>
<li><a href="ProductsList.php">Sport shoes </a></li>
<li><a href="ProductsList.php">Wedding clothes </a></li>
<li><a href="ProductsList.php">Underwear </a></li>
<li><a href="ProductsList.php">Leather </a></li>
<li><a href="ProductsList.php">Socks </a></li>
<li><a href="ProductsList.php">Pants </a></li>
</ul>
</li>
</ul>
but I am not sure which way is the best principals for generating the menu? should I use while loop and if or Case or for loop?
which way is the best way?
Thanks
Upvotes: 0
Views: 86
Reputation: 3862
can you please used this:
$gender = array('men','women');
$productlist = array('shirt'=>'shirt_url.php','t-shirt'=>'t-shirt_url.php','polo shirt'=>'polo_shirt.php');
foreach($gender as $individual) {
echo "<h2>{$individual}</h2>";
echo "<ul>";
foreach($productlist as $product_key=>$product_url) {
?>
<li><a href="<?php echo $product_url; ?>"><?php echo $product_key; ?></a></li>
<?php
}
echo "</ul>";
}
Upvotes: 0
Reputation: 5183
$gender = array('men','women');
$productlist = array('shirt','t-shirt','polo shirt','formal shoes','sport shoes','suit','underwear','socks','pants');
foreach($gender as $individual) {
echo "<h2>{$individual}</h2>";
echo "<ul>";
foreach($productlist as $product) {
<li><a href="ProductsList.php"><?php echo $product; ?></a></li>
}
echo "</ul>";
}
Upvotes: 1
Reputation: 609
You should have an array
$a=array('shirt','t-shirt','polo shirt','formal shoes','sport shoes','suit','underwear','socks','pants');
and use it like this:
<ul>
<h1>MEN</h1>
<?php foreach($a as $val) :?>
<li><a href="ProductsList.php"><?php echo $val; ?></a></li>
<?php endforeach ;?>
</ul>
<ul>
<h1>womaen</h1>
<?php foreach($a as $val) :?>
<li><a href="ProductsList.php"><?php echo $val; ?></a></li>
<?php endforeach ;?>
</ul>
Upvotes: 1