I want to comebine the use of a drop down list (with filters/options) with a search function (a search bar and a "Ok" button).
When I select a filter/option in the drop down list, as for example "Team". The drop down list then should be aware of that the list has changed to filter/option "Team". After this, I use the search function where I input the search term, like "USA" then press the Ok-button. Once the Ok-button is pressed, a sql-query like: SELECT * FROM mytable WHERE Team = 'USA'; is generated to fetch all the matched rows in the db "mytable".
- Select a filter, "Team".
- Select a team, "USA".
- Fetch matched rows with relevant data from the db mytable.
Hope I made myself understood better, thank you all for your time!
This is the code I have:
<html>
<head>
<title>AiFind</title>
<link rel="stylesheet" href="Style.css">
<script src="logic.js"></script>
</head>
<body>
<h1>AiFind</h1>
</body>
</html>
<?php
include "connection.php";
$sql = "SELECT * FROM mytable";
if (isset($_POST['search'])) {
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= " WHERE F_ar = '$search_term' ";
$sql .= " OR Postnr = '$search_term' ";
$sql .= " OR Postort = '$search_term' ";
$sql .= " OR Vardgivare = '$search_term' ";
$sql .= " OR Team = '$search_term' ";
$sql .= " OR Orsak = '$search_term' ";
$sql .= " OR Planerat_datum = '$search_term' ";
$sql .= " OR fran = '$search_term' ";
$sql .= " OR AAA_diam = '$search_term'; ";
}
$query = mysql_query($sql) or die(mysql_error());
?>
<form name="Select_filter" method="POST" action="VGR_data_display.php">
<select id="dropdown" name="filter">
<option value=""></option>
<option value="1">ID</option>
<option value="2">Alder</option>
<option value="3">Postnummer</option>
<option value="5">Postort</option>
<option value="6">Vårdgivare</option>
<option value="7">Planerat Datum</option>
<option value="8">Status</option>
<option value="9">AAA_diameter</option>
</select>
</form>
<!--search bar for search term input -->
<form name ="search_form" method="POST" action="VGR_data_display.php">
<input id="search_box" type="text" name="search_box" value="" />
<input id="submit" type ="submit" name ="search" value ="Ok">
</form>
<table style="margin:auto;" id="table" border='1'>
<tr>
<th>ID</th>
<th>F_ar</th>
<th>Postnr</th>
<th>Postort</th>
<th>Vardgivare</th>
<th>Team</th>
<th>Orsak</th>
<th>Planerat_datum</th>
<th>fran</th>
<th>AAA_diam</th>
</tr>
<?php while($row = mysql_fetch_array($query)) { ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['F_ar']; ?></td>
<td><?php echo $row['Postnr']; ?></td>
<td><?php echo $row['Postort']; ?></td>
<td><?php echo $row['Vardgivare']; ?></td>
<td><?php echo $row['Team']; ?></td>
<td><?php echo $row['Orsak']; ?></td>
<td><?php echo $row['Planerat_datum']; ?></td>
<td><?php echo $row['fran']; ?></td>
<td><?php echo $row['AAA_diam']; ?></td>
</tr>
<?php } ?>