Note that there are some explanatory texts on larger screens.

plurals
  1. PODropdown Menu to Query Database
    text
    copied!<p>First of I apologize if this is a dumb question - I'm just starting to pick up my php/mysql skills. I'm making a dropdown form with 3 dropdowns. I want to be able to trigger a query from the form. You select Part Type, Make, Model hit submit and a table of results is displayed. </p> <p>I have my form populated with 3 arrays and when you hit submit, I can echo the key of each selected item to the page: </p> <pre><code> echo '&lt;form action="dbBrowse.php" method="post"&gt;'; $mak = array (0 =&gt; 'Make', 'Ford', 'Freightliner', 'Peterbilt', 'Sterling', 'Mack', 'International', 'Kenworth', 'Volvo'); $mod = array (0 =&gt; 'Model', 'Argosy', 'Midliner'); $p = array (0 =&gt; 'Part', 'Radiator', 'Charge Air Cooler', 'AC'); echo '&lt;select name="drop1"&gt;'; foreach ($p as $key =&gt; $value) { echo "&lt;option value=\"$key\"&gt; $value&lt;/option&gt;\n"; } echo '&lt;/select&gt;'; echo '&lt;select name="drop2"&gt;'; foreach ($mak as $key =&gt; $value) { echo "&lt;option value=\"$key\"&gt; $value&lt;/option&gt;\n"; } echo '&lt;select/&gt;'; echo '&lt;select name="drop3"&gt;'; foreach ($mod as $key =&gt; $value) { echo "&lt;option value=\"$key\"&gt; $value&lt;/option&gt;\n"; } echo '&lt;select/&gt;'; echo '&lt;/form&gt;'; //echo keys of selection echo $_POST['drop1']; echo "&lt;br /&gt;"; echo $_POST['drop2']; echo "&lt;br /&gt;"; echo $_POST['drop3']; //these echo something like 1, 1, 3 etc. to my page </code></pre> <p>Where I'm getting lost is I'm looking to take the selected options and insert them into a query something like this: </p> <pre><code> $dropSearch = mysql_query('SELECT * FROM parts WHERE part= "$partTypeVar" . AND WHERE make = "$makeTypeVar" . AND WHERE model = "$modelTypeVar"'); $partTypeVar being the corresponding value to the key that is being returned from the array. </code></pre> <p>I'm driving myself crazy trying to figure out how to make that happen. Eventually I want to expand this further but just being able to create a mysql statement with the values selected would make my day right now. I understand the concept of what needs to happen but I'm unsure of how to accomplish it. Any help or pushes in the right direction would be greatly appreciated. </p>
 

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