Hope that all doing fine
I m working to build html form based on php and mysql.
What I m stuck in is: Select sub category based on category
For example I have 2 parent categories games and software and I have 4 sub categories 2 for games(action and stragedy ) and 2 for software(internet and anti-virus).
What I m looking for is when I select the games in category the sub-category only show the (action and stragedy) and when I select the software the sub-category only show the (Internet and anti-virus)
Parent games child1 action, child2 stragedy
Parent software child1 internet, child2 anti-virus
And here is php code
<?php
$conn=mysqli_connect("localhost","root","root","mene");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * from cates WHERE parent_name = 'main'";
$result = mysqli_query($conn,$sql);
$sql1 = "SELECT * from cates WHERE parent_name = 'category'";
$result1 = mysqli_query($conn,$sql1);
$sql2 = "SELECT * from cates WHERE parent_name = 'games'";
$result2 = mysqli_query($conn,$sql2);
$sql3 = "SELECT * from cates WHERE parent_name = 'software'";
$result3 = mysqli_query($conn,$sql3);
?>
<form action="action.php">
<a>choose the operating system</a>
<select name="main">
<option value="main">-----</option>
<?php
while($row = mysqli_fetch_array($result)) {
?>
<option value="<category"><?php echo $row['name']; ?></option>
<?php } ?>
</select>
<br><br>
<a>choose the category</a>
<select name="parent">
<option value="parent">-----</option>
<?php
while($row = mysqli_fetch_array($result1)) {
?>
<option value="<category"><?php echo $row['name']; ?></option>
<?php } ?>
</select>
<br><br>
<a>choose sub category</a>
<select name="child">
<option value="child">-----</option>
<php ?>
<?php
while($row1 = mysqli_fetch_array($result2)) {
?>
<option value="sub_category"><?php echo $row1['name']; ?></option>
<?php } ?>
</select>
<br><br>
<input type="submit">
</form>
<?php mysqli_close($conn); ?>
<php } ?>
any help?