Hello all, I was wondering if there is any way of searching in a database from drop-down boxes. I mean like this: and also if I can use the selection "any" for that. Please help I really need to know that. Thank you, -AT-XE
<? $submit = $_POST['submit']; if($submit){ // trying to submit the form $dropdown = $_POST['dropdown']; print "Drop down value is: " . $dropdown . "<br />"; $query = NULL; // need this for the loop scope if($dropdown == "any"){ $query = "select * from TABLE_NAME"; } else{ $query = "select * from TABLE_NAME where ROW='$dropdown'"; } $sql = mysql_fetch_assoc($query); $row = mysql_fetch_assoc($sql){ print $row['SOME_ROW']; } } else{ // show the form ?> <form action="<? $_SERVER['php_self']; ?>" method="post"> <select name="dropdown"> <option value="any">Any</option> <option value="something">Something</option> <option value="blah">Blah</option> </select> <input type="submit" name="submit" value="Submit!" /> </form> <? } ?> PHP: Haven't tested it, but that's the basic idea. It's part psuedo code part actual code, you just have to put it together (and work out any errors that I might have overlooked).
Say your second drop down is name "dropdown2", then in the php code you would have: $dropdown2 = $_POST['dropdown2']; // somewhere in an SQL statement $sql = "select * from TABLE_NAME where ROW='$dropdown1' and ROW='$dropdown2'; mysql_query($sql) or die(mysql_error()); PHP: Or something like that. Just basic passing of variables in PHP.