简体   繁体   中英

mysql query not showing result

can anyone help me to solve this mysql query problem

$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'");

I want use it as related articles

You have some wrong quotes and use concat for the like string

"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'"

请尝试以下操作:

$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."'");

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

$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'");

Kindly show your mysql connection string. here is an example:

<?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);
    }
}
?>

Try it out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM