2013-08-16 48 views
0

我想要多个下拉列表,它们在数据库中执行搜索并在网页的表格中回显信息。Ajax从第二选择和数据库中提取信息

从教程我管理这个,但只有一个选择的选择。我努力使第二个下拉列表改进搜索条件。

  • 下拉列表1应该是在数据库中搜索所选值的选项。

  • 下拉列表2应向AND添加AND条件并使用第二个值来优化搜索。

下面的代码不会从数据库中获取有关更改的任何信息。如果我删除AND语句,它将从数据库中提取信息。

HTML:

<!DOCTYPE html> 
<html> 

<head> 

    <title> Vault of Faults-Fault Search </title> 

    <link rel="stylesheet" type="text/css" href="mystyle1.css"> 

     <script src="dropdownfix1.js"></script> 

</head> 

<body> 

    <div id=container> 

    <div id=header> 
     <div id=headdiv> 


      <form id=login name="login" action="login.php" method="post"> 
        <fieldset class="field_set"> 
        <legend>Administrator Login:</legend> <!-- legeng tage creates a header title for the fieldset box, filedset pulls all data in the tag to gether with a box around it. --> 

        UserName: <input type="text" name="username"> <br> 

        Password:<br> <input type="password" name="password"> <br> 

        <input type="submit" value="Login"> <input type="Button" onClick="parent.location='addafix.php'" Value="Add a Fix"> 


        </fieldset> 
        </form> 


     </div> 
    </div> 

     <div id=content> 
     <div id=maincontent> 

     <div id=select> 
    <form> 
     <fieldset class="field_set2"> 
     <legend>Quicklink Vault of Faults Search</legend> 
     Product: 



    <select name="Product" onchange="showUser(this.value)"> 

     <option value="0">Select Product</option> 
     <option value="1">Merlin</option> 
     <option value="2">Encoder</option> 
     <option value="3">Mac Live</option> 
     <option value="4">Windows Live</option> 
     <option value="5">Windows S&F</option> 
     <option value="6">Mac S&F</option> 
     </select> 

     <select name="Product_Issue" onchange="showIssue(this.value)"> 

     <option value="0">Select Issue</option> 
     <option value="1">Preview</option> 
     <option value="2">Live Reciever</option> 
     <option value="3">Mac Live</option> 
     <option value="4">Windows Live</option> 
     <option value="5">Windows S&F</option> 
     <option value="6">Mac S&F</option> 
     </select> 






     <input type="submit" value="Search"> 
     </fieldset> 
    </form> 


    </div> 
      <div id=list> 
      <div id="txtHint"><b>Person info will be listed here.</b></div> 
      </div> 
     </div> 



     </div> 



    </div> 




</body> 

</html> 

的JavaScript:

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="+str,true); 
xmlhttp.send(); 
} 


function showIssue(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?p="+str,true); 
xmlhttp.send(); 
} 

PHP:

<?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."' AND 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 


?> 
+0

我认为问题出现在Javascript xmlhttp.open(“GET”,“getuser.php?p =”+ str,true); – Gustar

+0

你的意思是说,当你在查询中删除“AND”关键字时它就起作用了? – leonardeveloper

+0

我发现AND语句没问题,这个问题可能会传递 – Gustar

回答

0

我认为你需要Concat的下拉列表中的值。例如:

 <script type="text/javascript"> 
    function server(aform) 
    { 
    var xmlhttp; 
    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="+product_i.value ,true); 
    xmlhttp.send(); 
    } 
    </script> 
+0

信息它不起作用,不会引发任何的PHP – Gustar

相关问题