|
Posted by Kimmo Laine on 10/30/62 11:21
"Peter Butler" <peterbutler@iafrica.com> kirjoitti
viestissδ:y-CdndhlJdoeqkXfRVn-pg@is.co.za...
> 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.:
(a gazillion elseif's deleted)
> elseif ($a!=a && $b!=a && $c!=a && $d!=a && $e!=a && $f!=a && $g!=a &&
> $h!=a
> && $i!=a && $j!=a)
> { do thing XXXXXXX}
>
> - 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???
>
No, it can't. It is, in fact as you stated, the way dinosaurus' used to
code. That's why they are now extinct.
How ever, you've not provided enough information about what's inside the if
statememnts, to give a perfect answer. as soon as you describe a little more
about what's inside your if segments, there's no way to give you a decent
answer. What I can tell you right now is that you can evaluate the if's as a
number, and call a corresponding funtion.
I'd think the variables as a number:
$binary = (int)($a==a) . (int)($b==a) . (int)($c==a) . ... . (int)($j==a);
$number = bin2dec($binary);
Now $number is a numeral representation of the states of the variables. Now
you have a numbered function for each of the cases, named toDo_xxx() where
xxx is the corresponding number.
You call the function with a method called variable function. We form the
name of the function:
$todo_func = "toDo_$number"; // now $todo_func contains the name of the
function to be called.
now just callthe function via the variable.
$todo_func(); //Hands up, who knew that you can call a
// function with a variable that contains the name of the function?
By this you save the processor from not doing a gazillion if operations, you
simply jump to the function you want to call.
This is still not the final solution, since it still require a gazillion
functions. The true answer is to split the problem into the actual ten items
you have. You need to find a way to split the problem into:
if($a==a) {
// do AA thing
} else {
// do aa thing
}
if($b==b) {
// do BB thing
} else {
// do bb thing
}
..
..
..
if($j==j) {
// do JJ thing
} else {
// do jj thing
}
Where you now instead of 3k+ lines have actually just 20 or so. But as I
said, we'd need to know more about the nature of what is done inside each
if, to suggest a more logical way. In human-dinosaurus scale, what I've
offered you is still just a dinosaur who has learned to seek shelter from
rain.
Insufficient data...
--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears
eternal.erectionN0@5P4Mgmail.com
Navigation:
[Reply to this message]
|