 <?php
include("connection.php");
 $q = $_GET['q'];
$query="select * from subcategory where categorykey=".$q;
$records=$records=mysqli_query($connection,$query);
?>
 <select class="form-control" required name="subcategorykey">
     <option value="" selected='selected'>Select Sub Category</option>
 <?php
    while($row=mysqli_fetch_array($records)) 
    
    
         if($row2['subcategorykey']==$row['subcategorykey'])
        {
            echo "<option  selected value='".$row["subcategorykey"]."' >".$row["subcategoryname"]."</option>";
        }
        else 
        {
             echo "<option value='".$row["subcategorykey"]."'>".$row["subcategoryname"]."</option>";
        }


   
    

        ?>
</select> 