spike6511 Posted June 19, 2010 Share Posted June 19, 2010 Hi All, This is my first posting and I am a newbie to php... Here is my question. I have a page with two drop down list that are created by accessing two table, I have a third table that has all the information that I want to display with sortable columns, how do you take the values that you selected in the drop down lists and create a query that will return the answer to my web page. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/205265-drop-down-list/ Share on other sites More sharing options...
jd307 Posted June 19, 2010 Share Posted June 19, 2010 I assume what you are trying to do is basically: The two drop down lists are created from entries into the database tables. User clicks on their preffered selections A screen then displays the information based on the users selection If that is the case, then it seems you already have created the drop down lists. I would imagine these are part of a form, so when the user clicks the 'submit' button it would forward this information to the ACTION page? Take a look at the $_POST and $_GET methods in PHP, they will help you achieve what you are trying to do. One very good site for the basics is the following: http://www.tizag.com/phpT/postget.php Link to comment https://forums.phpfreaks.com/topic/205265-drop-down-list/#findComment-1074407 Share on other sites More sharing options...
bobby317 Posted June 19, 2010 Share Posted June 19, 2010 You will have to give your dropdown menu a name. <form> <select name="1234"> <option>1</option> <option>2</option> </select> </form Then use that name to get the selction made by the user and set it to a varable. <?php $selctions = ($_POST['1234']); ?> Then your query would be: SELECT * FROM table WHERE id = $selctions I think this is what you are trying to do. Hope this helps Link to comment https://forums.phpfreaks.com/topic/205265-drop-down-list/#findComment-1074409 Share on other sites More sharing options...
spike6511 Posted June 19, 2010 Author Share Posted June 19, 2010 Thanks for the reply, here is my code so far.... $quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category"); if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory"); }else{$quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory order by subcategory"); } echo "<form method=post name=f1 action='dd-check.php'>"; echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";} else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";} } echo "</select>"; echo "<select name='subcat'><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[subcategory]'>$noticia[subcategory]</option>"; } echo "</select>"; echo "<input type=submit value=Submit>"; echo "</form>"; this works but how do I put this into a query with the two selections to give me the results. Link to comment https://forums.phpfreaks.com/topic/205265-drop-down-list/#findComment-1074463 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.