Jump to content

Setting wildcard in drop-down list to search for "any"


dcibrando

Recommended Posts

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!

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";
}
?>

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?

 

 

 

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.