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! Quote Link to comment 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"; } ?> Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 dcibrando@yahoo.com thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.