This is my menu
<ul class="sub-menu">
<li><a href="product-category.html">Product 1</a></li>
<li><a href="product-category.html">Product 2</a>
<ul class="sub-menu">
<li><a href="product-category.html">P 21</a></li>
<li><a href="product-category.html">P 22</a></li>
<li><a href="product-category.html">P 23</a></li>
<li><a href="product-category.html">P 24</a></li>
</ul>
</li>
<li><a href="product-category.html">Product 3</a></li>
<li><a href="product-category.html">Product 4</a></li>
</ul>
Product1, Product2, Product3 are categories from category table. P 21, P 22, P 23, P 24 are subcategory of Product 2 in subcategory. All category dont have subcategory. category id saved in subcategory table.
CREATE TABLE IF NOT EXISTS category
(
cid
int(11) NOT NULL AUTO_INCREMENT,
cname
varchar(255) NOT NULL,
PRIMARY KEY (cid
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS subcategory
(
sid
int(11) NOT NULL AUTO_INCREMENT,
sname
varchar(255) NOT NULL,
cid
int(11) NOT NULL,
PRIMARY KEY (sid
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
How can i show it in menu by fetctching data from MySql with single query?
SQL
without knowing the structure of your database beforehand. – chriz