dcibrando Posted March 6, 2008 Share Posted March 6, 2008 I am such a rookie as this stuff... but apparently this is the code that takes the current date, adds 4 years, and then puts that in a drop down list with the previous 80 years function select_year($y) { $select = "<select name=year>\n\t"; for($i = date(Y) + 4; $i >= date(Y) - 80; $i--) { if($y == $i) { $select .= "<option value=\"$i\" selected>$i</option>\n\t"; } else { $select .= "<option value=\"$i\">$i</option>\n\t"; } } $select .= "</select>"; return $select; } What I am needing is also an option to search for any year...not just a specific one. How would I do that with this code? Here is the code that is called from the search page itself <tr> <td align=right class=style2 width="114">Graduate in:</td> <td width="152"><?=select_year($a1[year]);?></td> </tr> any help would be GREATLY appreciated!!!! The site is www.sullivancentralband.org/members Thanks! Link to comment https://forums.phpfreaks.com/topic/94689-setting-wildcard-in-drop-down-list-to-search-for-any/ Share on other sites More sharing options...
fnairb Posted March 6, 2008 Share Posted March 6, 2008 This is a two step but I can only show you the first as I don't know how your query is structured. <?php function select_year($y) { $select = "<select name=year>\n\t"; $select .= "<option value=\"any\" selected>[Any]</option>\n\t"; for($i = date(Y) + 4; $i >= date(Y) - 80; $i--) { if($y == $i) { $select .= "<option value=\"$i\" selected>$i</option>\n\t"; } else { $select .= "<option value=\"$i\">$i</option>\n\t"; } } $select .= "</select>"; return $select; } ?> Before you run your query throw in an if/else something like: <?php if ($_REQUEST['year'] == 'any') { $sql = "Your current query without any year filter at all"; } else { $sql = "Your current query as is"; } ?> Link to comment https://forums.phpfreaks.com/topic/94689-setting-wildcard-in-drop-down-list-to-search-for-any/#findComment-484858 Share on other sites More sharing options...
dcibrando Posted March 6, 2008 Author Share Posted March 6, 2008 thanks... so the first code you gave me would replace what I have now... I'm not quite sure I understand what to do with the second box of code if I gave you access to the site/code... could you or someone take a look? Link to comment https://forums.phpfreaks.com/topic/94689-setting-wildcard-in-drop-down-list-to-search-for-any/#findComment-484901 Share on other sites More sharing options...
fnairb Posted March 6, 2008 Share Posted March 6, 2008 The second block.... At some point your code is performing a search/filter with they year provided. I made the assumption that you are hitting a database with a query something along the lines of SELECT * FROM some_table WHERE year = $the_year_provided AND ... <?php if ($the_year_provided == 'any') { $sql = "SELECT * FROM some_table WHERE ..."; } else { $sql = "SELECT * FROM some_table WHERE year = $the_year_provided AND ..."; } ?> If it still isn't clear find the block of code that does the filter on year and throw it in the post, I'll clarify from there. Link to comment https://forums.phpfreaks.com/topic/94689-setting-wildcard-in-drop-down-list-to-search-for-any/#findComment-484923 Share on other sites More sharing options...
dcibrando Posted March 6, 2008 Author Share Posted March 6, 2008 ok I'll see if I can find it and post it here you can email me if you'd like [email protected] thanks! Link to comment https://forums.phpfreaks.com/topic/94689-setting-wildcard-in-drop-down-list-to-search-for-any/#findComment-485022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.