gpt4 book ai didi

php - 你怎么写“Select (all) From (table) Where posting=$posting except this posting?(Mysql)

转载 作者:可可西里 更新时间:2023-11-01 07:38:09 24 4
gpt4 key购买 nike

我想编写一个 Mysql 语句,从表(发布)中选择所有内容,其中标题类似于 $title 除了 $title 的标题。基本上我想显示某个帖子的所有相关帖子。我希望查询选择表中标题或详细信息中具有标题名称的所有帖子。但我不希望该帖子显示在相关帖子中。

//pseudocode
$query="Select * From posting Where title,detail, like %$title% except $title";

如何编写除外部分?

最佳答案

这是您需要的代码,但如果您有当前的帖子 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 . "
";

这是 ID 版本,更好:)

$title = mysql_real_escape_string($title);

$sql = "
SELECT *
FROM posting
WHERE
title LIKE '%" . $title . "%' AND
detail LIKE '%" . %title . "%' AND
id != " . (int)$post_id . "
";

关于php - 你怎么写“Select (all) From (table) Where posting=$posting except this posting?(Mysql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com