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!

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.