Fetch database table values in select's option tag based on value selection in php?

function gettaluka(dist_id)
{
if(dist_id){
$.ajax({
type:‘POST’,
url:‘ajaxData.php’,
// data : {‘name’:name1},
data:{‘dist_id’:dist_id},
success:function(data){ //console.log(html); return;
$(’#talukaplace’).html(data);
$(’#talukaplace’).html(’’+cost_name+’’);
$(’#talukaplace’).html(’’+bta_proj_name+’’);
// “+name+”
}
});
}else{
$(’#talukaplace’).html(‘Select Taluka’);

    }

}






                                                          <option value="0">Select District</option>
                                                          <option value="1">Cost Chargeable</option>
                                                          <option value="2">Project Name</option>
                                                          <option value="3">Other Recovery</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </td>
                                        <td>
                                                
                                            <div class="col-xs-12 col-sm-6 col-md-4 col-lg-6">      
                                                <div class="form-group">
                                                     <select class="form-control" name="talukaplace" id="talukaplace" required>
                                                        
                                                    <option value="0">Select Taluka</option> 
                                                </select> 

                                        
                                                </div>
                                            </div> 
                                        </td>
                                        </tr>

ajaxData.php

<?php //include("dbconnect.php"); $conn = mysqli_connect("localhost", "root", "", "india_tools_cmn"); $dist_id = $_POST["dist_id"]; $query = "select cost_name from hris_cost_centers"; $results = mysqli_query($conn, $query); $query1 = "select bta_proj_name from bta_project"; $results1 = mysqli_query($conn, $query1); // $rowCount = $query->num_rows; if(mysqli_num_rows($results)>0) { // echo 'Select Taluka'; while($row=mysqli_fetch_assoc($results)) { echo ''.$row['cost_name'].''; } } else{ // echo 'Select Project'; while($row1=mysqli_fetch_assoc($results1)) { echo ''.$row1['bta_proj_name'].''; } } ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service