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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomex1
Forum Commoner
Posts: 26
Joined: Sun Aug 16, 2009 11:34 am

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

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

Maybe. Or maybe not. Remember: readability is important too.

What's the code?
tomex1
Forum Commoner
Posts: 26
Joined: Sun Aug 16, 2009 11:34 am

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

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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.
Post Reply