Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to connect select dropdown in another select dropdown to create a combobox that has a value from the database?
    text
    copied!<p>I have 1 select dropdown and I want to create another select dropdown base on the value of select dropdown #1. For example, my dropdown #1 has the value of 13-001, 13-002, 13-003 and when I select in 13-001 it displays records in table from the database and has a column of po_number. I want to have another select dropdown that has a value of po_number depend on the value of dropdown #1.</p> <p>Just like this. Dropdown #1 13,-001, 13-002, 13-003</p> <p>Dropdown #2 when I select 13-001 the value of dropdown #2 is 111, 222, 333 base on the value taken from po_number column and displays only the records of dropdown#1 13-001 and dropdown #2 111 . I just add some id in my script but I don't know what's the next step.</p> <p>bid.php </p> <pre><code>&lt;script&gt; function showUser(str,ids) { var $txtHint = $('#txtHint'); if (str=="" || ids=="") { $txtHint.html(''); return; } $txtHint.load('bid_list.php?q='+str+'&amp;id='+ids) } &lt;/script&gt; &lt;/head&gt; &lt;body onload=showUser(str="ALL")&gt; &lt;?php $mysqli = new mysqli("localhost", "root", "", "app"); $result = $mysqli-&gt;query("SELECT bid FROM procurement WHERE bid LIKE '13-___' OR bid LIKE '1_-___' OR bid LIKE '2_-___' GROUP BY bid ORDER BY bid"); $option = ''; while($row = $result-&gt;fetch_assoc()) { $option .= '&lt;option value = "'.$row['bid'].'"&gt;'.$row['bid'].'&lt;/option&gt;'; } ?&gt; &lt;div style="text-align:center;"&gt; &lt;select name="users" onchange="showUser(this.value)" style="overflow:scroll;width:100px;"&gt; &lt;option value="ALL" selected='ALL'&gt;ALL&lt;/option&gt; &lt;?php echo $option; ?&gt; &lt;/select&gt; &lt;?php $mysqli = new mysqli("localhost", "root", "", "app"); $result = $mysqli-&gt;query("SELECT po_number FROM procurement WHERE po_number GROUP BY po_number ORDER BY po_number"); $option1 = ''; while($row = $result-&gt;fetch_assoc()) { $option1 .= '&lt;option value = "'.$row['po_number'].'"&gt;'.$row['po_number'].'&lt;/option&gt;'; } ?&gt; &lt;select style="overflow:scroll;width:100px;"&gt; &lt;option value="ALL" selected='ALL'&gt;ALL&lt;/option&gt; &lt;?php echo $option1; ?&gt; &lt;/select&gt; &lt;div id="txtHint"&gt;&lt;/div&gt; </code></pre> <p>bid_list.php</p> <pre><code>&lt;?php $mysqli = new mysqli("localhost", "root", "", "app"); $q = $_GET["q"]; $where = ''; if ( $q != 'ALL' ) { $where = " WHERE bid='$q' "; } $result1 = $mysqli-&gt;query(" SELECT bid, item_name, item_description, unit, unit_cost, quantity, supplier, po_number, po_date, counter, SUM(unit_cost*quantity) AS total_amount FROM procurement $where GROUP BY counter ORDER BY bid "); echo'&lt;table id="tfhover" cellspacing="0" class="tablesorter" style="text-transform:uppercase;"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th colspan="3" id="none" style="cursor: default;"&gt;&lt;/th&gt; &lt;th title="Item Name"&gt;Item Name&lt;/th&gt; &lt;th title="Item Description"&gt;Description&lt;/th&gt; &lt;th title="Example : Pc, Pcs, Box and Etc."&gt;Unit&lt;/th&gt; &lt;th title="Item Price"&gt;Unit Cost&lt;/th&gt; &lt;th title="Total Item Quantity"&gt;QTY&lt;/th&gt; &lt;th title="Total Price"&gt;Total Amount&lt;/th&gt; &lt;th title="Name of Supplier"&gt;Supplier&lt;/th&gt; &lt;th title="Purchase Order #"&gt;PO #&lt;/th&gt; &lt;th title="Purchase Order Date"&gt;PO Date&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt;'; echo'&lt;tbody&gt;'; while($row = $result1-&gt;fetch_assoc()){ if($row['bid'] != '') { echo'&lt;tr&gt; &lt;td align="center"&gt;&lt;a href="'.$_SERVER['PHP_SELF'].'?de='.$row["counter"].'" onclick="return confirm(\'Really want to delete ?\');"&gt;&lt;img src="images/del.png" border="0" width="10" height="10" title="Delete"&gt;&lt;/a&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;a class="fancybox" href="edit.php?pn='.$row["counter"].'"&gt;&lt;img src="images/edit.png" border="0" width="10" height="10" title="Edit"&gt;&lt;/a&gt;&lt;/td&gt; &lt;td align="center"&gt;&lt;a class="fancybox" href="comments.php?pn='.$row["counter"].'"&gt;&lt;img src="images/remarks.png" border="0" width="10" height="10" title="Remarks and Notes"&gt;&lt;/a&gt;&lt;/td&gt; &lt;td&gt;'.$row['item_name'].'&lt;/td&gt; &lt;td&gt;'.$row['item_description'].'&lt;/td&gt; &lt;td&gt;'.$row['unit'].'&lt;/td&gt; &lt;td&gt;'.number_format($row['unit_cost'], 2, '.', ',').'&lt;/td&gt; &lt;td&gt;'.$row['quantity'].'&lt;/td&gt; &lt;td&gt;'.number_format($row['total_amount'], 2, '.', ',').'&lt;/td&gt; &lt;td&gt;'.$row['supplier'].'&lt;/td&gt; &lt;td&gt;'.$row['po_number'].'&lt;/td&gt; &lt;td&gt;'.$row['po_date'].'&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt;'; } } echo "&lt;/table&gt;"; if (!$mysqli) { die('Connect Error: ' . mysqli_connect_error()); } mysqli_close($mysqli); ?&gt; </code></pre>
 

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