wabash Posted June 7, 2011 Share Posted June 7, 2011 I have drop downs which are generated from fields in a database. I'd like to implement an "Search All" selection into the dropdowns which searches all fields. I'm wondering what the best way to do this is? Select Plant Color:<br /> <select name="color"> <?php //for each row we get from mysql, echo a form input $querycolor="SELECT color FROM plantcolortable ORDER BY color"; $resultcolor = mysql_query ($querycolor); while($rowcolor = mysql_fetch_array($resultcolor)){ echo "<option value=\"$rowcolor[color]\">$rowcolor[color]</option>\n"; } ?> </select> </td> <td width="400" valign="top"> Select Plant Exposure:<br /> <select name="exposure"> <?php $queryexposure="SELECT exposure FROM plantexposuretable ORDER BY exposure"; $resultexposure = mysql_query ($queryexposure); while($rowexposure = mysql_fetch_array($resultexposure)){ echo "<option value=\"$rowexposure[exposure]\">$rowexposure[exposure]</option>\n"; } ?> Below is what my query looks like: <?php $query = "SELECT actualplanttable.id, actualplanttable.common1, actualplanttable.scientific, plantcolortable.color, plantexposuretable.exposure FROM actualplanttable JOIN plantcolorlinktable ON plantcolorlinktable.plant_id = actualplanttable.id AND plantcolortable.color = '$color' JOIN plantcolortable ON plantcolorlinktable.color_id = plantcolortable.id JOIN plantexposurelinktable ON plantexposurelinktable.plant_id = actualplanttable.id JOIN plantexposuretable ON plantexposurelinktable.exposure_id = plantexposuretable.id AND plantexposuretable.exposure = '$exposure' ORDER BY common1 ASC"; $result = mysql_query($query) or die(mysql_error()); if($row = mysql_fetch_array($result)) { echo "<big>Deer Resistant plants Results that are <b>$color:</b></big><br><br> "; echo "<b>".$row['common1']."</b> (". $row['scientific'].")<br> "; echo "Light Preference: ". $row['exposure']. "<br>"; echo "A blooming color: ". $row['color']; echo "<br /><br />"; while($row = mysql_fetch_array($result)) { echo "<b>".$row['common1']."</b> (". $row['scientific'].")<br> "; echo "Light Preference: ". $row['exposure']. "<br>"; echo "A blooming color: ". $row['color']; echo "<br /><br />"; } } else { echo "No results found<br /><br />"; } echo '<a href="http://www.website">Start a new Search</a>'; } ?> Any help or guidance is greatly appreciated. Thanks! Bill... Link to comment https://forums.phpfreaks.com/topic/238709-drop-down-search-all-feature/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.