Professional Web Applications Themes

Anoying problem with multiple 'elseif' variations... - PHP Development

OK, lets see... I have 10 text boxes to enter keywords into a form page (The master search page) These boxes are either set or not set when passed to the result page as set or unset variables. Depending on which variables have been set, the set variables are used to formulate the query. I have got this to work perfectly... but I am convinced that I'm using the dinosour method. ie.: if ($a==a && $b==a && $c==a && $d==a && $e==a && $f==a && $g==a && $h==a && $i==a && $j==a) { do thing AA} elseif ($a!=a && $b==a ...

  1. #1

    Default Anoying problem with multiple 'elseif' variations...

    OK, lets see...

    I have 10 text boxes to enter keywords into a form page (The master search
    page)

    These boxes are either set or not set when passed to the result page as set
    or unset variables.

    Depending on which variables have been set, the set variables are used to
    formulate the query.

    I have got this to work perfectly... but I am convinced that I'm using the
    dinosour method. ie.:

    if ($a==a && $b==a && $c==a && $d==a && $e==a && $f==a && $g==a && $h==a &&
    $i==a && $j==a)
    { do thing AA}
    elseif ($a!=a && $b==a && $c==a && $d==a && $e==a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing BB}
    elseif ($a==a && $b!=a && $c==a && $d==a && $e==a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing CC}
    elseif ($a==a && $b==a && $c!=a && $d==a && $e==a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing DD}
    elseif ($a==a && $b==a && $c==a && $d!=a && $e==a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing EE}
    elseif ($a==a && $b==a && $c==a && $d==a && $e!=a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing FF}
    elseif ($a==a && $b==a && $c==a && $d==a && $e==a && $f!=a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing GG}
    elseif ($a==a && $b==a && $c==a && $d==a && $e==a && $f==a && $g!=a && $h==a
    && $i==a && $j==a)
    { do thing HH}
    elseif ($a==a && $b==a && $c==a && $d==a && $e==a && $f==a && $g==a && $h!=a
    && $i==a && $j==a)
    { do thing II}
    elseif ($a==a && $b==a && $c==a && $d==a && $e==a && $f==a && $g==a && $h==a
    && $i!=a && $j==a)
    { do thing JJ}
    elseif ($a==a && $b==a && $c==a && $d==a && $e==a && $f==a && $g==a && $h==a
    && $i==a && $j!=a)
    { do thing KK}

    /* then different combos of two's */
    elseif ($a!=a && $b!=a && $c==a && $d==a && $e==a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing BB}
    elseif ($a!=a && $b==a && $c!=a && $d==a && $e==a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing BB}
    elseif ($a!=a && $b==a && $c==a && $d!=a && $e==a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing BB}
    elseif ($a!=a && $b==a && $c==a && $d==a && $e!=a && $f==a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing BB}
    elseif ($a!=a && $b==a && $c==a && $d==a && $e==a && $f!=a && $g==a && $h==a
    && $i==a && $j==a)
    { do thing BB}
    etc, etc, etc...........

    /* then different combos of threes */
    elseif ($a!=a && $b!=a && $c!=a...
    {do thing wada-wada...
    elseif ($a!=a && $b!=a && $c==a...
    {do thing wada-wada...
    elseif ($a!=a && $b!=a && $c==a...
    {do thing wada-wada...
    etc, etc, etc...........

    /* then different combos of fours */
    elseif ($................................................ .......
    elseif ($................................................ .......
    elseif ($................................................ .......
    etc, etc, etc...........

    /* then different combos of fives */
    elseif ($................................................ .......
    elseif ($................................................ .......
    elseif ($................................................ .......
    etc, etc, etc...........

    /* then different combos of sixes */
    elseif ($................................................ .......
    elseif ($................................................ .......
    elseif ($................................................ .......
    etc, etc, etc...........

    /* then different combos of sevens */
    elseif ($................................................ .......
    elseif ($................................................ .......
    elseif ($................................................ .......
    etc, etc, etc...........

    /* then different combos of eights */
    /* then different combos of nines */

    /* until... three thousand six hundred and forty-nine lines of code later
    we get to make*/
    elseif ($a!=a && $b!=a && $c!=a && $d!=a && $e!=a && $f!=a && $g!=a && $h!=a
    && $i!=a && $j!=a)
    { do thing X}

    - OK... For those eagle eyes out there... I actually have 14 different
    fields in which to set variables... two pairs of which are grouped together
    as max/min values,
    but I do really have 3649 lines of stuff that is slowing down my DUAL PIII
    500 on saves.

    This can't be the right way... really???




















    Peter Guest

  2. #2

    Default Re: Anoying problem with multiple 'elseif' variations...

    Peter Butler wrote: 


    if all your different AA, BB, CC etc. "things to do" are completely
    different, then they WILL all need to be coded.

    However, if they are all just variations of a single bit of code - which
    could be made to take the vars passed from the form as arguments, you'd
    have a much shorter/better program.

    All your comparisons are binary, i.e. $x is either ==a or !=a, therefor
    your 14 or however many fields, can all be represented as a single
    binary 'number', which you can pass as an argument

    You really do need to provide some more information, like what is
    actaully is you're trying to do.


    Andrew
    Andrew Guest

  3. #3

    Default Re: Anoying problem with multiple 'elseif' variations...

    Peter Butler wrote:
     
    [snip]

    Haven't got time to look at this in detail, but my first thought is that,
    rather than using separate variables - $a, $b etc - you should probably be
    using an array - $mystuff['a'], $mystuff['b'] - you could then use
    array_walk or foreach to cycle through the array, perhaps in a function to
    which you pass the 'odd man out' or other conditions as parameters.

    +

    Phil Guest

  4. Moderated Post

    Default Re: Anoying problem with multiple 'elseif' variations...

    Removed by Administrator
    Kimmo Guest
    Moderated Post

  5. #5

    Default Re: Anoying problem with multiple 'elseif' variations...

    I noticed that Message-ID: <dbb2jk$rqi$kolumbus.fi> from
    Kimmo Laine contained the following:
     

    <fx: puts hand up>

    --
    Geoff Berrow 0110001001101100010000000110
    001101101011011001000110111101100111001011
    100110001101101111001011100111010101101011
    Geoff Guest

  6. #6

    Default Re: Anoying problem with multiple 'elseif' variations...

    On Sat, 16 Jul 2005 00:25:25 +0200, "Peter Butler"
    <com> wrote:
     
    Can you give us an example? I may have a better way to do this. See
    a post I made in several threads earlier in response to your previous
    posting.

    But my method may not be appropriate depending on what you are trying
    to do.

    Do you have a web page we could look at?

    Please post the url to this sample page.


    Best regards,

    Al
    http://www.affordablefloridainsurance.com
    http://www.americanbestmortgages.com
    http://www.americanaffordablelifeinsurance.com
    AF Guest

  7. #7

    Default Re: Anoying problem with multiple 'elseif' variations...

    Why not use a SWITCH statement, would be cleaner and much easier to read.
    Plus, if you position them right then you can skip a few break statements
    and make a code a bit compressed.

    "Peter Butler" <com> wrote in message
    news:co.za... 


    Hello Guest

Similar Threads

  1. it's anoying!!!
    By igorski in forum Macromedia Shockwave
    Replies: 0
    Last Post: March 28th, 02:02 AM
  2. Anoying text outlines
    By John in forum Adobe Illustrator Windows
    Replies: 8
    Last Post: August 25th, 05:34 PM
  3. failing elseif construct
    By Bert in forum PHP Development
    Replies: 5
    Last Post: August 12th, 08:44 PM
  4. Anoying WEP notice. Can I disable?
    By bryan in forum Windows Networking
    Replies: 6
    Last Post: July 31st, 02:33 PM
  5. If - ElseIf - SQL Select... ASP YES.. PHP NO ???
    By James in forum PHP Development
    Replies: 3
    Last Post: June 26th, 08:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139