stevew Posted July 7, 2012 Share Posted July 7, 2012 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET" name=""> Pick a color:<br /> <select name="color"> <option value="blue">blue</option> <option value="green">green</option> </select> Pick another color<br /> <select name="color2"> <option value="yellow">yellow</option> <option value="brown">brown</option> </select> <input type="Submit" name="Submit"> <?php $data = mysql_query("SELECT * FROM tbl WHERE color='.$_GET.' AND color2='.$_GET[color2].'")or die(mysql_error()); $result = mysql_fetch_array( $data ); This is the part I need some help with. I have 3 fields in the table... id, color, color2. I would like to print or echo all the data matching the search input: (results for drop down input: blue, yellow) id 15 color blue color2 yellow ______________ id 22 color blue color2 yellow etc Link to comment https://forums.phpfreaks.com/topic/265354-combining-simple-drop-down-search/ Share on other sites More sharing options...
stevew Posted July 7, 2012 Author Share Posted July 7, 2012 Actually I also need help with my select statement: $data = mysql_query("SELECT * FROM tbl WHERE color='.$_GET.' AND color2='.$_GET[color2].'")or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/265354-combining-simple-drop-down-search/#findComment-1359895 Share on other sites More sharing options...
Fadion Posted July 8, 2012 Share Posted July 8, 2012 Are you having any errors or it's just that you have no idea on how to print results from MySQL? It isn't clear at all. First of all, you'll need to escape input to prevent sql injections. After that, it's as simple as working with arrays. <?php if ($_GET) { $color = mysql_real_escape_string($_GET['color']); $color2 = mysql_real_escape_string($_GET['color2']); $results = mysql_query("SELECT * FROM tbl WHERE color='$color' AND color2=$color2"); $values = mysql_fetch_assoc($results); echo $values['id'].'<br>'; echo $values['color'].'<br>'; echo $values['color2'].'<br>'; } ?> Link to comment https://forums.phpfreaks.com/topic/265354-combining-simple-drop-down-search/#findComment-1360164 Share on other sites More sharing options...
Pikachu2000 Posted July 8, 2012 Share Posted July 8, 2012 This is the same problem as your other threads. Locked. Link to comment https://forums.phpfreaks.com/topic/265354-combining-simple-drop-down-search/#findComment-1360165 Share on other sites More sharing options...
Recommended Posts