> I have this very large and long if statement:
> if
>  (!empty($_SESSION['add']['type'])
>  && !empty($_SESSION['add']['start_date']
>  && !empty($_SESSION['add']['end_date'])
>  && !empty($_SESSION['add']['name'])
>  && !empty($_SESSION['add']['county'])
>  && !empty($_SESSION['add']['discription'])
>  && !empty($_SESSION['add']['StartingDay'])
>  && !empty($_SESSION['add']['StartingMonth'])
>  && !empty($_SESSION['add']['StartingYear'])
>  && !empty($_SESSION['add']['EndingDay']})
>  && !empty($_SESSION['add']['EndingMonth'])
>  && !empty($_SESSION['add']['EndingYear']))
>  {//run the insert query}
> else
>  {//show error since one or more fields above are blank}
> was wondering if there was really any way to condense that down to
> something any better? all fields in the form that those came from are
> required...


Doubt you're going to make it smaller, but you can make it more readable.

As I understand it, !empty is redundant (at least, it's always worked for
me, but I'm no expert).  Plus the use of AND should make it more
human-readable, like so:
if (    $_SESSION['add']['type']
    AND $_SESSION['add']['start_date']
    AND $_SESSION['add']['end_date']
    AND $_SESSION['add']['name']
    AND $_SESSION['add']['county']
    AND $_SESSION['add']['discription']
    AND $_SESSION['add']['StartingDay']
    AND $_SESSION['add']['StartingMonth']
    AND $_SESSION['add']['StartingYear']
    AND $_SESSION['add']['EndingDay']
    AND $_SESSION['add']['EndingMonth']
    AND $_SESSION['add']['EndingYear'])
{//run the insert query}
else
{//show error since one or more fields above are blank}

Personally, I'd clean it up a tiny bit more:
$add = $_SESSION['add'];
if (    $add['type']
    AND $add['start_date']
...
{//show error since one or more fields above are blank}
unset ($add);

Again, I'm no expert, but hopefully that'll help.
/dev/idal

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to