I have three select boxes which populate with data from the database.
First they are acquiring data from the DB fine, but when it comes to editing the second select box is taking the default value from the database.
Here is the code for the Main Category :
<select name="cat" id="cat">
<?php
$res="SELECT * from cat order by catname";
$stmt = $conn->prepare( $res );
$stmt->execute();
while($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option value=$cate>$result[catname]</option>";
}
?>
</select>
Sub Category:
<select name="scid" id="scid">
<?php
if ($row['psubcat']>0) {
$resi="SELECT * from subcat where sid=$row[psubcat]";
$stmt = $conn->prepare( $resi );
$stmt->execute();
while($results = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option value=$row[psubcat]>$results[scname]</option>";
}
}
?>
</select>
Sub Sub Category:
<select name="sscid" id="sscid">
<?php
if ($sscate>0) {
$resis="SELECT * from ssubcat where sid=$sscate";
$stmt = $conn->prepare( $resis );
$stmt->execute();
while($resultss = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<option value=$sscate>$resultss[sscname]</option>";
}
}
?>
</select>
</div>
Categories change dynamically depending on key change using ajax.