i有一个SQL表(产品),如以下格式
<table style="height: 44px; width: 340px;">
<tbody>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">id</td>
<td style="width: 217px; height: 18px;">colName</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">5</td>
<td style="width: 217px; height: 18px;">Backup Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">26</td>
<td style="width: 217px; height: 18px;">Backup Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">27</td>
<td style="width: 217px; height: 18px;">Backup Normal</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">28</td>
<td style="width: 217px; height: 18px;">Backup Plus Slim</td>
</tr>
<tr style="height: 17px;">
<td style="width: 109px; height: 17px;">29</td>
<td style="width: 217px; height: 17px;">wd Backup Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">30</td>
<td style="width: 217px; height: 18px;">Backup-Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">38</td>
<td style="width: 217px; height: 18px;">wd(Backup Plus Slim)</td>
</tr>
</tbody>
</table>
我想要精确匹配的行,而搜索备份加上SLIM ST2R122300 在产品表中(即单词)。我将如何在SQL查询中实现它。
可以使用Full-Text Index
检查此DOC
或者使用LIKE
'%[^a-z]SearchValue[^a-z]%'
或LIKE '%SearchValue%'
SELECT * FROM PRODUCTS WHERE COLNAME LIKE '%[^a-z]SearchValue[^a-z]%';
还为什么您需要数据库连接?我认为您使用jQuery
$("#searchInput").keyup(function() {
//split the current value of searchInput
var data = this.value.split(" ");
//create a jquery object of the rows
var jo = $("#fbody").find("tr");
if (this.value == "") {
jo.show();
return;
}
//hide all the rows
jo.hide();
//Recusively filter the jquery object to get results.
jo.filter(function(i, v) {
var $t = $(this);
for (var d = 0; d < data.length; ++d) {
if ($t.is(":contains('" + data[d] + "')")) {
return true;
}
}
return false;
})
//show the rows that match.
.show();
}).focus(function() {
this.value = "";
$(this).css({
"color": "black"
});
$(this).unbind('focus');
}).css({
"color": "#C0C0C0"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="searchInput" value="Type To Filter">
<br/>
<table style="height: 44px; width: 340px;">
<thead>
<tr>
<th>Id</th>
<th>ColName</th>
</tr>
</thead>
<tbody id="fbody">
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">5</td>
<td style="width: 217px; height: 18px;">Backup Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">26</td>
<td style="width: 217px; height: 18px;">Backup Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">27</td>
<td style="width: 217px; height: 18px;">Backup Normal</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">28</td>
<td style="width: 217px; height: 18px;">Backup Plus Slim</td>
</tr>
<tr style="height: 17px;">
<td style="width: 109px; height: 17px;">29</td>
<td style="width: 217px; height: 17px;">wd Backup Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">30</td>
<td style="width: 217px; height: 18px;">Backup-Plus Slim</td>
</tr>
<tr style="height: 18px;">
<td style="width: 109px; height: 18px;">38</td>
<td style="width: 217px; height: 18px;">wd(Backup Plus Slim)</td>
</tr>
</tbody>
</table>
select * from products where colName='Backup Plus Slim ST2R122300';
' *'(无引号) - 返回所有列。
产品 - 表的名称。
colname-列的名称。