如何从MySql中用php搜索匹配值
我这里有一个问题,关于如何从数据库中搜索精确的值。这里我的代码功能正常,但问题是,当我搜索值时,例如,我搜索T1,然后结果显示T1、T11、T12、T13等等。我只显示与T1匹配的值。下面是我的代码如何从MySql中用php搜索匹配值,php,mysql,search,Php,Mysql,Search,我这里有一个问题,关于如何从数据库中搜索精确的值。这里我的代码功能正常,但问题是,当我搜索值时,例如,我搜索T1,然后结果显示T1、T11、T12、T13等等。我只显示与T1匹配的值。下面是我的代码 <?php include_once("mysql_connect.php"); $output1 = ''; ?> <?php if(isset($_POST['select'])) { $selectq = $_POST['select']; $query = mysql
<?php
include_once("mysql_connect.php");
$output1 = '';
?>
<?php
if(isset($_POST['select'])) {
$selectq = $_POST['select'];
$query = mysql_query("SELECT * FROM asset_a WHERE Tag_no LIKE '%$selectq%' or
Speciality LIKE '%$selectq%' ") or die("could not search!");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'There was no search results!';
}else{
while($row = mysql_fetch_array($query)) {
$tag = $row['Tag_no'];
$special = $row['Speciality'];
$output1 .= $special;
}
}
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Testing</title>
</head>
<body>
<p>
<form name="form1" method="post" action="testq.php" >
<label for="textfield" style="font-family:'Gill Sans', 'Gill Sans MT', 'Myriad Pro',
'DejaVu Sans Condensed', Helvetica, Arial, sans-serif; font-size:20px">
Tag No:</label>
<select name="select" id="select" class="textfields" >
<option value="0">-- Select your tag no --</option>
<?php
$getallAsset_a = mysql_query("SELECT * FROM asset_a ");
while($viewallAsset_a = mysql_fetch_array($getallAsset_a)){
?>
<option id="<?php echo $viewallAsset_a ['Tag_id'];?>"><?php echo
$viewallAsset_a['Tag_no']; ?></option>
<?php } ?>
<input type="image" name="submit" id="submit" src="../Search.png"
formaction="testq.php" >
</p>
</select>
<p>
<label for="textfield">Text Field:</label>
<input type="text" name="special" id="textfield"value="<?php print ("$output1");?>" >
</p>
</form>
</body>
</html>
如果要找到确切的值,为什么首先要使用“LIKE”?旁注:从输入中删除formaction=testq.php。尝试“%$selectq%”而不使用“%$selectq%”这样的“%$selectq”。谢谢大家!它的工作。我只需要删除符号%。非常感谢=