Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>Edit : Pseudo code for option 1</p> <pre><code>&lt;select name="group_id"&gt; &lt;option vaule="1"&gt;1&lt;/option&gt; &lt;option vaule="2"&gt;2&lt;/option&gt; &lt;/select&gt; $('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&lt;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); </code></pre> <p>I hope you can find the right syntax.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload