Learn how to show category and subcategory in core php with mysql.
Firstly you need to crate tow table one for category and second for subcategory.
<?php
mysql_connect('localhost','root','password')or die('could not connect');
mysql_select_db('category_subcategory')or die('could not select db');
$sql="select * from category";
$query = mysql_query($sql);
echo"<ul>";
while($row = mysql_fetch_assoc($query))
{
$id =$row['id'];
echo"<li>".$row['category'];
$sql1="select * from subcategory where category_id='$id'";
$query1 = mysql_query($sql1);
echo"<ul>";
while($row1 = mysql_fetch_assoc($query1))
{
echo '<li>'.$row1['subcategory'].'</li>';
}
echo'</ul>';
echo '</li>';
}
echo'</ul>';
?>
Your output would be like this
Firstly you need to crate tow table one for category and second for subcategory.
<?php
mysql_connect('localhost','root','password')or die('could not connect');
mysql_select_db('category_subcategory')or die('could not select db');
$sql="select * from category";
$query = mysql_query($sql);
echo"<ul>";
while($row = mysql_fetch_assoc($query))
{
$id =$row['id'];
echo"<li>".$row['category'];
$sql1="select * from subcategory where category_id='$id'";
$query1 = mysql_query($sql1);
echo"<ul>";
while($row1 = mysql_fetch_assoc($query1))
{
echo '<li>'.$row1['subcategory'].'</li>';
}
echo'</ul>';
echo '</li>';
}
echo'</ul>';
?>
Your output would be like this



0 comments:
Post a Comment