mysql查询没有显示结果

时间:2016-09-22 06:01:37

标签: php mysql

任何人都可以帮我解决这个mysql查询问题

$rela=mysql_query("SELECT * 
      FROM  pvl_posts 
      WHERE (title LIKE '%$title%' OR post LIKE '%$title%'') 
      OR (title LIKE '%$post%' OR post LIKE '%$post%'') 
      AND id != '$id'");

我想用它作为相关文章

4 个答案:

答案 0 :(得分:1)

你有一些错误的引号,并使用concat作为类似的字符串

"SELECT * 
  FROM  pvl_posts 
  WHERE (title LIKE concat('%', '$title','%') OR post LIKE concat('%','$title' ,'%') )
  OR (title LIKE concat('%' , '$post', '%')   OR post LIKE concat('%','$post','%') )
  AND id != '$id'"

答案 1 :(得分:0)

请尝试以下方法:

$rela=mysql_query("SELECT * FROM  pvl_posts WHERE (title LIKE '%".$title."%' OR post LIKE '%".$title."%') OR (title LIKE '%".$post."%' OR post LIKE '".$post."') AND id != '".$id."'");

答案 2 :(得分:0)

试试这个,有两个',删除它。

$rela=mysql_query("SELECT * FROM  pvl_posts WHERE (title LIKE '%$title%' OR post LIKE '%$title%') OR (title LIKE '%$post%' OR post LIKE '%$post%') AND id != '$id'");

答案 3 :(得分:0)

请显示您的mysql连接字符串。这是一个例子:

<?php
$mysqli = new mysqli("localhost", "root", "", "database_name");
$query = "SELECT * FROM  pvl_posts WHERE (title LIKE '%$title%' OR post LIKE '%$title%') OR (title LIKE '%$post%' OR post LIKE '%$post%') AND id != '$id'";
$rows = $mysqli->query($query);
if ($rows->num_rows > 0) {
    while ($row = $rows->fetch_assoc()) {
        // do something with row variable here.
        var_dump($row);
    }
}
?>

尝试一下。