Page 1 of 1

How can i make my search form as user friendly as possible

Posted: Thu Sep 03, 2009 2:12 pm
by tomex1
Hello,
I am building an application which runs a query in the backend depending on how many fields the user fills. At the moment, I have a lot of 'if' statements which checks if each field is filled and then runs the query. I have not even completed this but I have used quite a lot of if statements! Is there any other way of achieving this which will be more efficient than the if statements?

Cheers

Re: How can i make my search form as user friendly as possible

Posted: Thu Sep 03, 2009 2:29 pm
by requinix
Maybe. Or maybe not. Remember: readability is important too.

What's the code?

Re: How can i make my search form as user friendly as possible

Posted: Thu Sep 03, 2009 2:35 pm
by tomex1
tasairis wrote:Maybe. Or maybe not. Remember: readability is important too.

What's the code?

Basically, I have a lot of if statement like

if((strlen($fielda > 0)) && (strlen($fieldb == 0)) && (strlen($fieldc > 0)) && (strlen($fieldd == 0)) && (strlen($fieldd == 0))
{
//run query
}
else if......

Bear in mind that the above if statement is just for when one of the fields is filled by the user. You can imagine how many else ifs I will end up having in order to compare the other possible combinations.

Re: How can i make my search form as user friendly as possible

Posted: Thu Sep 03, 2009 3:12 pm
by requinix
Probably some of those strlens can be dropped: "do this if fields A and B aren't empty". If they filled in A, B, and D then you'd ignore D and do that action.

How about posting the entire code? Then we can see other patterns and ways to optimize it.