Reply to Re: form search

Your name:

Reply:


Posted by news.tpg.com.au on 05/28/05 07:42

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
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация