I'm currently trying to incorporate a LIKE
clause into my SQL select statement and take out the associating MATCH/AGAINST clause.
我目前正在尝试将LIKE子句合并到我的SQL select语句中,并取出关联的MATCH / AGAINST子句。
Ive tried many different variations of it and feel that I'm missing something since none have seemed to work yet.
我尝试了很多不同的变化,觉得我错过了一些东西,因为似乎还没有。
The full php Page is
完整的PHP页面是
<?php
if(isset($_POST['searchQuery']))
{
require_once('config.inc.php');
$search_query=$_POST['searchQuery'];
$sql = 'SELECT * from tbl_fish where MATCH(fish_name,size_name,cat_name) AGAINST(:search_query)';
$statement = $connection->prepare($sql);
$statement->bindParam(':search_query', $search_query, PDO::PARAM_STR);
$statement->execute();
if($statement->rowCount())
{
$row_all = $statement->fetchall(PDO::FETCH_ASSOC);
header('Content-type: application/json');
echo json_encode($row_all);
}
elseif(!$statement->rowCount())
{
echo "no rows";
}
}
?>
I've tried statements like this
我试过这样的陈述
$sql = 'SELECT * from tbl_fish WHERE (fish_name LIKE '%'searchQuery'%')';
But I have yet to come up with a working one. These results are being queried from an android application so I'm wondering if I'm missing something more than just changing that one statement. I was following a tutorial for this and it all works except when I try to change the parameters for the query.
但我还没有想出一个有效的工作。这些结果正在从一个Android应用程序中查询,所以我想知道我是否缺少一些东西,而不仅仅是改变那一个语句。我正在关注这个教程,除非我尝试更改查询的参数,否则一切正常。
Hoping to get some feedback from you guys. Thanks.
希望得到你们的一些反馈。谢谢。
1 个解决方案
#1
1
For build a proper like clause you can use concat
为了构建一个合适的类似条款,你可以使用concat
$sql = "SELECT * from tbl_fish WHERE fish_name LIKE concat ( '%', :searchQuery, '%')";
and for match the 3 columns you should use OR
并匹配3列你应该使用OR
$sql = "SELECT * from tbl_fish
WHERE fish_name LIKE concat ( '%', :searchQuery, '%')
or size_name LIKE concat ( '%', :searchQuery, '%')
or cat_name LIKE concat ( '%', :searchQuery, '%');";
#1
1
For build a proper like clause you can use concat
为了构建一个合适的类似条款,你可以使用concat
$sql = "SELECT * from tbl_fish WHERE fish_name LIKE concat ( '%', :searchQuery, '%')";
and for match the 3 columns you should use OR
并匹配3列你应该使用OR
$sql = "SELECT * from tbl_fish
WHERE fish_name LIKE concat ( '%', :searchQuery, '%')
or size_name LIKE concat ( '%', :searchQuery, '%')
or cat_name LIKE concat ( '%', :searchQuery, '%');";