全文导致错误的结果

时间:2014-05-09 13:16:28

标签: php mysql phpmyadmin

mysqli_real_escape_string使程序错误。

我有一个全文列title。 我完成后,全文功能不在phpMyadmin中工作。

PHPMYADMIN

 - **id|title** 
 - 1|cool boy
 - 2|cool bottle
 - 3|cool guy
 - 4|hot man

更新

file1.php

   //from a form

   $str = $_POST['q'];
   $str=mysqli_real_escape_string($con,$str);
   mysqli_query($con,"insert into tbl(title)values($str)");

file2.php

$str = $_GET['q'];

$data = mysqli_query($con,"select * from tbl where match(title)against('$str')");
while($row = mysqli_fetch_assoc($data)){
   //do stuff . but yields nothing
}

2 个答案:

答案 0 :(得分:0)

试试这个

  select * from tbl where title LIKE '%cool%'

编辑:如果您想进行全文搜索,请更改此

  against('cool')

 against('cool' IN BOOLEAN MODE)

在MySQL中,有三种类型的全文搜索:

  • 布尔搜索
  • 自然语言搜索(默认使用)
  • 查询扩展搜索

来自MySQL manual entry

DEMO HERE

EDIT2:

在file1.php中执行

   session_start(); //this will be in very top of your file
   $str = $_POST['q'];
   $_SESSION['str'] = $str;
   $str=mysqli_real_escape_string($con,$str);
   mysqli_query($con,"insert into tbl(title)values($str)");

在file2.php中

   session_start(); //this will be in very top of your file
   $str = $_SESSION['str'];
   $data = mysqli_query(.........

答案 1 :(得分:0)

select * from tbl where title LIKE 'cool%'

在字符串/变量

之后只添加一个%
相关问题