Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Input

Status
Not open for further replies.

cogdev

MIS
Nov 30, 2001
85
US
I have a form that has about 4 drop downs and check boxes.
When I submit these selections I have to do a series of if then else to find out which of the options have been selected. This can be quite long as the user can choose either 1, none or any number of options.

Is there a way to store thes responses in some kind of array so that I do not have to manually check them. That way I can run" select data from table where key(array) = array(key)..something like that.
Is there a better way of doing what I have in mind?
sample code
Code:
if (($selfac =='F' and $selrank =='R')) 
{
$result = mysql_query("select * from tbl_faculty");
}
else {
	if ($selfac != 'F'  and $selrank!='R')
	{
		$result = mysql_query("select * from tbl_faculty where fac_name = '$selfac' and rank= '$selrank'");
		}
		else {
		$result = mysql_query("select * from tbl_faculty ");
		}}
 
I'm not exactly sure what you're asking. The code logic you've posted can by simplified to:

Code:
if ($selfac != 'F' && $selrank != 'R')
{
	$result = mysql_query("select * from tbl_faculty where fac_name = '$selfac' and rank= '$selrank'");
}
else
{
	$result = mysql_query("select * from tbl_faculty ");
}


But if you want multiple inputs to appear in a single array, name them as if they are PHP array references:

Code:
<html><body>
<form method="post" action="show_post.php">
	<input type="checkbox" [b]name="foo[1]"[/b] value="A"><br>
	<input type="checkbox" [b]name="foo[2]"[/b] value="B"><br>
	<input type="checkbox" [b]name="foo[3]"[/b] value="C"><br>
	<input type="submit">
</form>
</body></html>

If this form is submitted with the first and third checkbox checked, $_POST looks something like:

Code:
Array
(
    [foo] => Array
        (
            [a] => 1
            [c] => 3
        )

)


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
if ($selfac != 'F' && $selrank != 'R')


can you explain what this does? Please...
 
It means:
if $selfac doesn't equal 'F' and $selrank doesn't equal 'R'

If it aint broke, redesign it!
 
I strongly recommend that you use "&&" instead of "and" in this situation.

The two operators have different precedence ("&&" has higher precedence than "and"), and interchanging them can cause difficult-to-debug logical errors.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top