我有 2 个下拉列表,分别称为 ddl1 和 ddl2,
当我选择 ddl1 时,它会填充该搜索的整个结果。
当我选择 ddl2 来优化搜索时,没有进行任何更改。
如何从以下 sql 查询中实现精细搜索
<?php
$q=$_GET["q"];
$p=$_GET["p"];
require 'connection.php';
mysqli_select_db($con,"Faults" );
//where statement in the sql syntax will select where in db to get infor, use AND to add another condition
$sql="SELECT Products.Product_Name, Versions.Version, Platform.Platform_Name, Issues.Issue, Issues.Sub_Issue, Issues.Fix
FROM Solutions
INNER JOIN Products
ON Solutions.Product = Products.Product_id
INNER JOIN Versions
ON Solutions.Product_Version = Versions.Version_id
INNER JOIN Platform
ON Solutions.Product_Platform = Platform.Platform_id
INNER JOIN Issues
ON Solutions.Product_Issue = Issues.Issue_id
WHERE Product = '".$q."'
OR (Product_Issue = '".$p."'
OR Product_Issue ='".$p."')";
$result = mysqli_query($con,$sql);
//below is the echo statment to create the results in a table format, list collumn titles
echo "<table id=tables border='1'>
<tr>
<th>Products</th>
<th>Version</th>
<th>Platform</th>
<th>Issue</th>
<th>Sub Issue</th>
<th>Fix</th>
</tr>";
//below is script to list reults in a table format, $row [row name on table]
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['Product_Name'] . "</td>";
echo "<td>" . $row['Version'] . "</td>";
echo "<td>" . $row['Platform_Name'] . "</td>";
echo "<td>" . $row['Issue'] . "</td>";
echo "<td>" . $row['Sub_Issue'] . "</td>";
echo "<td><a href=\"idfix.php?Fix=" . nl2br($row['Fix']) . "\">Fix</a></td>";
echo "</tr>";
}
echo "</table>";
// below closes the coonection to mysql
?>
JS代码
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+ product.value +"&" +"p="+ issue.value ,true);
xmlhttp.send();
}