我想在 PHP 中创建高级搜索选项。我正在根据下拉框和单选按钮检索值。我想知道如何基于这些生成查询,例如如何首先从列表框和单选按钮中获取值。第二件事是我想知道如何在查询中包含多个变量,或者只是将查询完全留空。
例如:我应该按包含(R、Mahout、Storm、Python、Splunk)的组件类型过滤组件域(电信、公用事业、零售、BFSI、旅行、医疗保健)使用权(知识产权、无权)然后是杂项值比如按字母顺序排序,按版本等。
问题是可以从组件域和组件类型中选择多个值。或者它可以留空。我如何根据选择的内容进行搜索?如果有多个值,我如何相应地修改我的 php 查询?
我已经粘贴了下面的代码:你能像至少给我一个关于如何为组件类型生成查询并为其生成多个值的示例查询一样指导我吗
<!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>
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cerebra", $con);
$sql="select name from details";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
$query=mysql_query($sql,$con);
$names=array();
$index=0;
while($row=mysql_fetch_array($query)){
$names[$index]=$row[0];
$index++;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
var availableTags = <?php echo json_encode($names); ?>;
$( "#search" ).autocomplete({
source: availableTags
});
});
</script>
<style type="text/css">
.basictab{
padding: 3px 0;
margin-left: 0;
font: bold 16px Sans-serif;
border-bottom: 1px solid black;
list-style-type: none;
text-align: left; /*set to left, center, or right to align the menu as desired*/
}
.basictab li{
display: inline;
margin: 0;
}
.basictab li a{
text-decoration: none;
padding: 3px 7px;
margin-right: 3px;
border: 1px solid gray;
border-bottom: none;
background-color: #FFFFFF;
color: #2d2b2b;
}
.basictab li a:visited{
color: #00F;
}
.basictab li a:hover{
color: #C60;
}
.basictab li a:active{
color: black;
}
.basictab a:selected{ /*selected tab effect*/
position: relative;
top: 1px;
padding-top: 4px;
background-color: #DBFF6C;
color: #06F;
}
fieldset{
padding: 1em;
font:90%/1 Verdana, Geneva, sans-serif;
}
</style>
<script>
function view(){
document.getElementById("view").style.display="";
}
function auth(){
var pwd=prompt("Enter the password:","Password")
}
function hide(){
document.getElementById("view").style.diplay="none";}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="assets/style.css" />
<!--<link rel="stylesheet" type="text/css" href="assets/prettify.css" />-->
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<!--<script type="text/javascript" src="assets/prettify.js"></script>-->
<script type="text/javascript" src="src/jquery.multiselect.js"></script>
<script type="text/javascript">
$(function(){
$("select").multiselect();
});
</script>
</head>
<body onload="hide(); prettyPrint();" id="test" >
<div><h1 style="font-family:Geneva, sans-serif; color:#036">Component Registry</h1></div>
<div id=tab>
<ul class="basictab">
<li><a href="search.php">SEARCH</a></li>
<li><a href="add.php">ADD</a></li>
</ul>
</div>
<div>
<form id="form1" name="form1" method="post" action="">
<p>
<label for="search"></label>
<input type="text" name="search" id="search" />
<a id=2 href="#" onclick="view()">Search</a>
</p>
<fieldset>
<legend>Filter by:</legend>
<div id=1>
<table><tr><td><p>
<label>Component Type:</label></td>
<td><select title="Basic example" multiple="multiple" name="example-basic" size="5">
<option value="option1">Sgoop</option>
<option value="option2">Monet</option>
<option value="option3">Hive</option>
<option value="option4">Mahout</option>
<option value="option5">R</option>
<option value="option6">Storm</option>
<option value="option7">Flume</option>
<option value="option8">Solr</option>
<option value="option9">Python</option>
<option value="option10">Splunk</option>
<option value="option11">Ruby</option>
<option value="option12">perl</option>
</select>
</p></td></tr>
<tr><td><p>
<label>Component Domain:</label></td>
<td><select title="Basic example" multiple="multiple" name="examplebasic2" size="5">
<option value="Telecom">Telecom</option>
<option value="Utility">Utility</option>
<option value="BFSI">BFSI</option>
<option value="Travel">Travel</option>
<option value="Health Care">Health Care</option>
<option value="Retail">Retail</option>
<option value="Technology">Technology</option>
<option value="Government">Government</option>
<option value="Manufacturing">Manufacturing</option>
<option value="Education">Education</option>
</select></td></tr>
<tr><td><p>Usage Rights:</td>
<td><input type="radio" name="radio2" id="right" value="right" />
<label for="right">Intellectual Property</label>
<input type="radio" name="radio2" id="right2" value="right2" />
<label for="right2">No rights reserved</label>
</p></td></tr>
<tr><td><p>Miscellaneous:</td>
<td><input type="radio" name="radio3" id="misc" value="misc" />
<label for="misc">Sort Alphabetically</label>
<input type="radio" name="radio3" id="misc2" value="misc" />
<label for="misc2">Sort by Upload date</label>
<input type="radio" name="radio3" id="misc3" value="misc3" />
<label for="misc3">Sort by Versions</label>
</p></td></tr>
</table> </div></fieldset>
<div id="view" style="display:none">
<table width="457" border="1" align="center">
<tr>
<td width="117">Component Name</td>
<td width="59">Type</td>
<td width="60">Domain</td>
<td width="56">Rights</td>
<td width="72">Download</td>
<td width="53">Delete</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input type="radio" name="radio" id="12" value="1" />
<label for="12"></label></td>
<td><input type="radio" name="radio" id="122" value="1" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input type="radio" name="radio" id="2" value="2 />
<label for="2"></label></td>
<td><input type="radio" name="radio" id="123" value="1" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><input type="submit" name="1" id="13" value="Download" /></td>
<td><input type="submit" name="13" id="132" value="Delete" onclick="auth()" /></td>
</tr>
</table>
</div>
<p> </p>
<p> </p>
</form>
</body>
</html>