Interlinked dropdown list

i am working with interlinked dropdown list i.e on selection of one dropdown list ajax call generated and populated another dropdown list and so on.

So my problem is with data coming from server side,on selection of each dropdown list i want to filter the available-results also,but the data that coming from server side get appended to show div i.e dropdown-list items and results-items.i only want to append results-items to show div.
client side code

      var country_code = $(this).val();
                $('#city').html('<option value="">Select state first</option>'); 
        $('#state').html('<option value="">Select country first</option>');
        $('#city').html('<option value="">Select state first</option>'); 

server side code

if(isset($_POST["country_code"]) && !empty($_POST["country_code"])){
    $id = 1;
$code = $_POST['country_code'];
$code = mysqli_real_escape_string($conn,$code);
$query = "SELECT * FROM plus2_state WHERE country_code = '$code' ORDER BY state ASC";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
$rowCount = mysqli_num_rows($result);
if($rowCount > 0){
    while($row = mysqli_fetch_array($result)){ 
        echo '<option class="state_option" value="'.$row['state_id'].'">'.$row['state'].'</option>';        
    echo '<option class="state_option" value="">State not available</option>';
$query_1 = "SELECT * from content where country_code = '$code' ORDER BY emp_name ASC";
$result_1 = mysqli_query($conn,$query_1) or die(mysqli_error($conn));
$row_count = mysqli_num_rows($result_1);
$_SESSION['result'] = array();
if($row_count > 0 )
    while($content_rows = mysqli_fetch_array($result_1))
        echo "<div class='result'><div class='col-md-3 photo-grid' style = 'float:left'>
            <div class = 'well well-sm'><h4><small>".$content_rows['emp_name']."</small></h4></div></div></div>";
            $_SESSION['result'][$id] =  array('name' => $content_rows['emp_name']);
    echo "<div class = 'result'>no results found</div>";
$_SESSION['country_code'] = $code ;

So is the problem the data that is being returned by the server side PHP script? Or are you having a problem with the JS that shows the data?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.