|
Posted by Koncept on 08/31/06 23:33
In article <1157048879.574032.104880@i3g2000cwc.googlegroups.com>,
kenoli <kenoli@igc.org> wrote:
> I am designing a database with several "key word" columns. Users
> wanting to search the database will enter terms into html form fields
> from drop down menus populated from existing lookup tables or by adding
> their own terms which may, in some cases, be inserted into the lookup
> tables for subsequent users. Some of the form fields may be left
> empty.
>
You could try something like this as a template:
( N.B. Don't forget to properly check and prepare your vars for the
query! )
----------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css" media="screen">
/* <![CDATA[ */
label{width:150px;float:left}
#submit{margin:1em 0 0 150px}
/* ]]> */
</style>
<title></title>
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF']?>"
method="post">
<label for="selectopts">Number:</label>
<select name="proc[number]">
<option
label = "select"
value = "null"
selected = "selected">[select]</option>
<option label="1" value="1">1</option>
<option label="2" value="2">2</option>
<option label="3" value="3">3</option>
</select>
<br />
<label for="firstname">First Name:</label>
<input
type = "text"
id = "firstname"
name = "proc[firstname]" />
<br />
<label for="lastname">Last Name:</label>
<input
type = "text"
id = "firstname"
name = "proc[lastname]" />
<br />
<label for="phone1">Phone:</label>
<input
type = "text"
id = "firstname"
name = "proc[phone1]" />
<br />
<input
type = "submit"
name = "submit"
value = "Process »"
id = "submit" />
</form>
<?php
if($_POST["proc"]):
foreach($_POST["proc"] as $k => $v):
if(!empty($v)):
switch($k):
case 'number':
preg_match('/^\d+$/',$v)
&& $q[] = "number = '{$v}'";
break;
case 'firstname':
$q[] = "first_name = '{$v}'";
break;
case 'lastname':
$q[] = "last_name = '{$v}'";
break;
case 'phone1':
$q[] = "phone = '{$v}'";
break;
default:
trigger_error("Unrecognized input",
E_USER_ERROR);
break;
endswitch;
endif;
endforeach;
if($q):
echo "<code>SELECT * FROM table WHERE ",
implode(" AND ",$q),"</code>";
endif;
endif;
?>
</body>
</html>
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Navigation:
[Reply to this message]
|