显示另一个选定的标签,其中包含所选组名的联系号码

I'v a following html select tag which get group name from mysql db. But I want to show another select tag to get all contact number of selected group name from same db table.

Html select tag

<tr>
<td>Group name</td>
<td>
<select name="group_name" class="td">
<option value="">--Select Group--</option>
    <?php
    $class = mysql_query("SELECT group_name, gid FROM e_contact");      
    while($res =  mysql_fetch_array($class))
    {           
        $group_name_e = $res['group_name'];
        $gid_e = $res['gid'];
        ?>
        <option value="<?php echo "$group_name_e | $gid_e"; ?>"  <?php 
if(isset($_POST['group_name']) && $_POST['group_name'] == "$group_name_e | $gid_e") echo 
'selected = "selected"'; ?>> <?php echo $group_name_e; ?></option>";
        <?php
    }
    ?>
</select>
</td>
</tr>

Mysql e_contact table structure:

  cid     group_name     gid     contact_name     contact_no

   1      Shibbir         1      alex             01674458522
   2      Evan            2      Elux             01674455852  
   3      Shibbir         1      Babu             0174557851
   4      Maya            3      minar            01714455852

how can i get this contact numbers using php ? Any solution or idea ? Thank you very much.

As per my understanding, you want to display all the groups in the dropdown menu, and after user selects a group from the dropdown menu, you want to display contact numbers corresponding to that group. This is not possible just with php. You have to use javascript also.

PHP executes on page load, It doesn't know what option is selected by the user, after user selects a group, you can't connect to database in that same page and get contact numbers. You can do it in two ways.

1) Display all groups in the dropdown menu, and on change of the group, make an ajax call to the server to get the contact numbers corresponding to that group and display them.

2) Get all the contact numbers along with groups while loading the page and store them in a javascript object and on change of group in the dropdown menu, get the contact number from javascript object and display it.

Edit : Pseudo code for option 1

<select name="group_id">
    <option vaule="1">1</option>
    <option vaule="2">2</option>
</select>

$('select[name=group_id]').on('change', function() {
    var group_id = $(this).val();
    $.ajax({
        url : 'yoursite/getContactNumber.php?gid='+group_id,
        type : 'GET',
        dataType : 'json',
        success : function(data) {
            for(var i=0;i<data.length;i++) {
                $('#contact_number').append(data[i].contact_number);                 //append contact number to body.. check syntax
            }
        }
    });
});

getContactNumber.php

$contact_number = mysql_query("SELECT group_name, gid, contact_number FROM e_contact WHERE gid = ". $_GET['gid']);
echo json_encode($contact_number);

I hope you can find the right syntax.

Use as follows :

<tr>
<td>Group name</td>
<td>
    <?php
    $class = mysql_query("SELECT group_name, gid, contact_no FROM e_contact");      
    while($res =  mysql_fetch_array($class))
    {           
        $group_name_e = $res['group_name'];
        $gid_e = $res['gid'];
        $contact_no = $res['contact_no'];
        $optoinGname .= '<option value="'.$group_name_e.'">'.$group_name_e.'</option>';
        $optoinCno .= '<option value="'.$contact_no.'">'.$contact_no.'</option>';
    }
    ?>
<select name="group_name" class="td">
    <option value="">--Select Group--</option>
    <?php echo $optoinGname; ?>
</select>
<select name="contact_no" class="td">
    <option value="">--Select Contact--</option>
    <?php echo $optoinCno; ?>
</select>
</td>
</tr>

I have removed option selected code i am sure you can add them again in the option strings.