--- William Piper <[EMAIL PROTECTED]> wrote:
> Wade Smart wrote:
> >
> >
> > 20080827 1416 GMT-6
> >
> > This helping the school is full time job!!
> >
> > The code Im working with uses a lot of $_GET instead of $_POST and its not
> > acting like what I thought it would act like - I have no hands on time with
> > $_GET until just this project.
> >
> > if( ($_GET['sports_type'] == "football" || "basketball" || "track") ||
> > $_GET['transfer_sport'] == "wrestling"){ }
> >
> > As I read this if sports_type equals any of the following three OR
> > transfer_sport equals wrestling do this.
> >
> > Right?
> >
> > But even when NONE of those are equal for either one the code is executing.
> >
> > Wade
>
> Should be:
>
> if( ($_GET['sports_type'] == "football" || $_GET['sports_type'] ==
> "basketball" || $_GET['sports_type'] == "track") ||
> $_GET['transfer_sport'] == "wrestling"){ }
To make it easier to read and more flexible, I would probably do something
like:
$sports_types = array("football", "basketball", "track");
$transfer_sports = array("wrestling");
if (in_array(strtolower($_GET['sports_type']), $sports_types) or
in_array(strtolower($_GET['transfer_sport']), $transfer_sports))
{
# ...
}
Now, any way you can populate the arrays will work. However, you probably want
to further cleanse the $_GET inputs and perhaps this should be done before the
if() statements.
switch...case statements are also useful for this sort of thing.
James