Query based on multiple search options.

A

Anonymous

Guest
I am having difficulty designing a query that takes several options as arguments. I am querying a database for surgery information that I want to be based on a combination of And...Or combinations. For example...

There are 10 fields in the database and I want the user to search based upon any combination of the 10. Since a seperate query for every possiblity is not feasible I need a solution...if there is one. Here is my form for user input to the query criteria:

<form action="query.php" method="post">
<table align="center" border="1">
<tr>
<td align="center">
<strong>Surgery Date</strong><br />

<input type="text" name="sx_date" size="10" maxlength="10" />
</td>

<td align="center">
<strong>Patient Name</strong><br />
<input type="text" name="name" size="30" maxlength="30" />
</td>

<td align="center">
<strong>Eye</strong><br />

<select name="eye">
<option value="" selected="true"></option>
<option value="OD">OD</option>
<option value="OS">OS</option>
</select>
</p>
</td>

<td align="center">

<strong>IOL Type</strong><br />
<select name="iol_type">
<option value="" selected="true"></option>
<option value="Technis">Technis</option>
<option value="Natural">Natural</option>
<option value="Sensar">Sensar</option>
<option value="Array">Array</option>

</select>
</td>

<td align="center">
<strong>IOL Power</strong><br />
<input type="text" name="iol_power" size="5" maxlength="5" />
</td>

<td align="center">
<strong>Diopters</strong><br />

<input type="text" name="astig_diopters" size="5" maxlength="5" />
</td>

<td align="center">
<strong>Axis</strong><br />
<input type="text" name="astig_axis" size="3" maxlength="3" />
</td>

<td align="center">
<strong>ECP</strong><br />

<input type="checkbox" name="ecp" value="ECP" />
</td>

<td align="center">
<strong>YAG</strong><br />
<input type="checkbox" name="yag" value="YAG" />
</td>
</tr>

<tr>

ThanX !
:D
 
you make a single query
but...
before you do that..., you check for posted paramteters... and depending upon that... you append the where clauses eg...
Code:
$sql = 'select * from tablename';
if (isset($_POST['name']) && !empty($_POST['name']))
{
   $sql .= " where name = {$_POST['name']}";
}
//.... and so on...
 
Back
Top