Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

form search
I'm new to PHP & MySQL. I want to be able to process a form with 4
input fields according to how many fields are filled out. If only one
is filled, it searches on that, if two it searches accordingly etc. I
have all the select statements for each instance working I just don't
know the best way to call them. Would if be an if else statement (
perhaps if(!isset???) that would call each script or is there a better
way. Any help would be appreciated


Report this thread to moderator Post Follow-up to this message
Old Post
overflo@telstra.com
05-27-05 08:58 AM


Re: form search
Set a value depending on whether fields are filled out.

Return the values of the fields to your PHP script using $_POST and set
these to variables such as $a, $b, $c and $d.
Use strlen() on these variables to determine if they are non empty.

Set a variable called $sum to use the values 1, 2, 4 and 8 respectively for
each field filled in.

i.e
$sum = 0;
if (strlen($a) > 0), $sum = $sum+1;
if (strlen($b) > 0), $sum = $sum+2;

You can sum these together to get the 16 possible combinations from 0 to 15
(i.e. 2x2x2x2 = 16).
You can then use a switch statement based on the sum such as

switch($sum)
case 0: // some action if no fields were completed
case 1:
case 2:
...
case 15: // some action if all fields were completed
default:

You can also choose to omit or cancel out of certain cases by using the
break statement.
This method is good if you want to expand on your forms later on.
A new strlen() test and a quick copy and paste will duplicate the existing
cases for a new field

Just change the numbers for the cases and alter the commands to take the new
field into account and you're done.
Lots of flexibility in terms of performing different tasks however bear in
mind that because it doubles with each additional field, this could take a
long time to process with more than 10 fields.

2 ^ 4 = 16
2 ^ 10 = 1024 - (2 ^ 6 or 64 times longer)

Oh, and of course your original variables of $a, $b, $c, $d etc can still be
used for any data manipulation you like.

Hope that helped...
Now for my question :p

<overflo@telstra.com> wrote in message
news:1117172890.336511.224560@o13g2000cwo.googlegroups.com...
> I'm new to PHP & MySQL. I want to be able to process a form with 4
> input fields according to how many fields are filled out. If only one
> is filled, it searches on that, if two it searches accordingly etc. I
> have all the select statements for each instance working I just don't
> know the best way to call them. Would if be an if else statement (
> perhaps if(!isset???) that would call each script or is there a better
> way. Any help would be appreciated
>



Report this thread to moderator Post Follow-up to this message
Old Post
news.tpg.com.au
05-28-05 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:20 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.