[英]How do you write "Select (all) From (table) Where posting=$posting except this posting? (Mysql)
I want to write a Mysql statement that selects all from a table(posting) where title is like $title except for the title of $title. 我想写一条Mysql语句,从标题(如$ title)除$ title的标题之外的表(发布)中选择所有内容。 Basically I want to display all related posting of a certain posting.
基本上我想显示某个发布的所有相关发布。 I want the query to select all the postings in the table that has the title name in the title OR detail.
我希望查询选择表中标题或详细信息中具有标题名称的所有发布。 But I don't want the posting to display in the related postings.
但我不希望该帖子显示在相关帖子中。
//pseudocode
$query="Select * From posting Where title,detail, like %$title% except $title";
how do I write the except part? 我如何写除外部分?
This is the code you need, although it will be better if you have the current post id and just have something like WHERE id != " . (int)$current_post_id . "
这是您所需的代码,尽管如果您具有当前的帖子ID并且仅具有
WHERE id != " . (int)$current_post_id . "
$title = mysql_real_escape_string($title);
$sql = "
SELECT *
FROM posting
WHERE
title LIKE '%" . $title . "%' AND
detail LIKE '%" . %title . "%' AND
title != " . $title . "
";
Here is the ID version, way better :) 这是ID版本,更好:)
$title = mysql_real_escape_string($title);
$sql = "
SELECT *
FROM posting
WHERE
title LIKE '%" . $title . "%' AND
detail LIKE '%" . %title . "%' AND
id != " . (int)$post_id . "
";
EDIT: If you want LIKE '%$title%' AND != '$title' then: 编辑:如果您想像'%$ title%'和!='$ title',则:
SELECT * FROM posting
WHERE title LIKE '%$title%' AND detail LIKE '%$title%' AND title != '$title';
else 其他
SELECT * FROM posting
WHERE title LIKE '%$title%' AND detail LIKE '%$title%' AND title NOT LIKE '%$title%';
Are you sure that's correct? 您确定正确吗?
LIKE '%$title%' AND NOT LIKE '%$title%'
is a contradiction. LIKE '%$title%' AND NOT LIKE '%$title%'
是矛盾的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.