嘿伙计我正在创建一个包含两个参数的搜索引擎,第一个是TEXT
,第二个是RADIO BOX
。然而,我的查询似乎知道无线电值是什么,但似乎往往完全忽略它。我不能完全把手指放在我出错的地方。任何帮助将不胜感激。
<?php
session_start();
?>
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
<!-- Basic Page Needs
================================================== -->
<meta charset="utf-8">
<title>site title</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
================================================== -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- CSS
================================================== -->
<link rel="stylesheet" href="stylesheets/base.css">
<link rel="stylesheet" href="stylesheets/skeleton.css">
<link rel="stylesheet" href="stylesheets/layout.css">
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
function search(partialSearch,level){
$.ajax({type: "POST",url:"php/bigsearch.php",data: {partialSearch: partialSearch, level: level},success:function(result){
$("#results").html(result);
}});#
alert("dsfsgdfg");
};
</script>
<!-- Favicons
================================================== -->
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
</head>
<body>
<!-- Primary Page Layout
================================================== -->
<!-- Delete everything in this .container and get started on your own site! -->
<div class="container">
<?php include 'navigation.php' ?>
<div class="sixteen columns">
<img src="images/glass.jpg" alt=""/>
<h3 class="forum">Search the site</h3>
<form action="bigsearch.php" method="POST" >
<label><input type="radio" name="level" value="beginner">Beginner</label>
<label><input type="radio" name="level" value="intemediate">Intemediate</label>
<label><input type="radio" name="level" value="advanced">Advanced</label>
<label><input type="radio" name="level" value="idontcare" checked="checked">I Don't Care</label>
<input type="text" name="partialSearch"/>
<input type="submit" name="search"/>
</form>
<div id="results">
<?php
include 'php/config.php';
$partialSearch = "%".$_POST['partialSearch']."%";
$check = $_POST['level'];
if($check == "idontcare"){
$stmt = $mysqli->prepare("SELECT VideoId, Name, Level FROM videos WHERE Keywords LIKE ? OR Name LIKE ? ");
$stmt->bind_param('ss',$partialSearch,$partialSearch);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($VideoId,$Name,$Level);
}else{
$stmt = $mysqli->prepare("SELECT VideoId, Name, Level FROM videos WHERE Keywords LIKE ? OR Name LIKE ? AND Level = ?");
$stmt->bind_param('sss',$partialSearch,$partialSearch,$check);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($VideoId,$Name,$Level);
}
$length = strlen($partialSearch);
if($length < 3){
}else{
if($stmt->num_rows == 0){
echo "No results";
}else{
while($rows = $stmt->fetch()){
echo "<a href=../view.php?post=".$VideoId.">".$Name."</a>";
echo "<p>".$Level."</p>";
}}}
?>
</div>
</div>
</div>
</div><!-- container -->
<!-- End Document
================================================== -->
</body>
</html>
答案 0 :(得分:0)
<!-- Delete everything in this .container and get started on your own site! -->
<div class="container">
<?php include 'navigation.php' ?>
<div class="sixteen columns">
<img src="images/glass.jpg" alt=""/>
<h3 class="forum">Search the site</h3>
<form action="bigsearch.php" method="POST" >
<label><input type="radio" name="level" value="beginner">Beginner</label>
<label><input type="radio" name="level" value="intemediate">Intemediate</label>
<label><input type="radio" name="level" value="advanced">Advanced</label>
<label><input type="radio" name="level" value="idontcare" checked="checked">I Don't Care</label>
<input type="text" name="partialSearch"/>
<input type="submit" name="search"/>
</form>
<div id="results">
<?php
include 'php/config.php';
$partialSearch = "%".$_POST['partialSearch']."%";
$check = $_POST['level'];
if($check == "idontcare"){
$stmt = $mysqli->prepare("SELECT VideoId, Name, Level FROM videos WHERE Keywords LIKE ? OR Name LIKE ? ");
$stmt->bind_param('ss',$partialSearch,$partialSearch);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($VideoId,$Name,$Level);
}else{
$stmt = $mysqli->prepare("SELECT VideoId, Name, Level FROM videos WHERE (Keywords LIKE ? OR Name LIKE ?) AND Level = ?");
$stmt->bind_param('sss',$partialSearch,$partialSearch,$check);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($VideoId,$Name,$Level);
}
$length = strlen($partialSearch);
if($length < 3){
}else{
if($stmt->num_rows == 0){
echo "No results";
}else{
while($rows = $stmt->fetch()){
echo "<a href=../view.php?post=".$VideoId.">".$Name."</a>";
echo "<p>".$Level."</p>";
}}}
?>
</div>
</div>
</div>
</div><!-- container -->
<!-- End Document
================================================== -->
</body>
</html>
尝试这个我猜你的sql命令的主要问题,因为你在Where子句中混合了OR / AND你应该在()之间组合OR来修复它
希望这个答案可以帮助你