Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check below Code : </p> <p><strong>First Listbox code</strong> Would be as below: </p> <pre><code>&lt;form id="form1" name="form1" method="post" action="&lt;?php $_SERVER['PHP_SELF']?&gt;"&gt; Drop1 &lt;?php $mysqli = new mysqli("localhost", "root", "", "lists"); $result = $mysqli-&gt;query("SELECT * FROM main_list GROUP BY id ORDER BY id"); $option = ''; while ($row = $result-&gt;fetch_assoc()) { $option .= '&lt;option value = "'.$row['value'].'"&gt;'.$row['value'].'&lt;/option&gt;'; } ?&gt; &lt;select id="main" name="main"&gt; &lt;option selected=selected&gt;Choose&lt;/option&gt; &lt;?php echo $option; ?&gt; &lt;/select&gt; &lt;div id="sublist"&gt;&lt;/div&gt; &lt;input type="submit" name="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p><strong>Jquery code</strong> Would be as below: </p> <pre><code> $('#main').change(function(){ $.ajax({ url : 'secondlist.php', data :{mainlist_id : $(this).val()}, dataType:'html', type:'POST', success:function(data){ $('#sublist').html(data); } }); }); </code></pre> <p>Code in <strong>secondlist.php</strong> page : </p> <pre><code> $mysqli = new mysqli("localhost", "root", "", "lists"); $result1 = $mysqli-&gt;query("SELECT * FROM sub_list as s, main_list as m where s.category_id = m.id and s.category_id = $_POST['mainlist_id'] GROUP BY value ORDER BY id "); $option1 = ''; while ($row = $result1-&gt;fetch_assoc()) { $option1 .= '&lt;option value = "'.$row['value'].'"&gt;'.$row['value'].'&lt;/option&gt;'; } $output = 'Drop2 '; $output .= '&lt;select name="sub" id="sub"&gt;'; $output .= '&lt;option value=" " disabled="disabled" selected="selected"&gt;Choose one&lt;/option&gt;'; $output .= $option1; $output .= '&lt;/select&gt; '; echo $output; exit; ?&gt; </code></pre> <p>Some changes may be required related to your requirements, but it will definitely work for you.</p> <p>Let me know if you have any query!</p> <p>Thanks!</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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