【发布时间】:2013-09-27 19:40:37
【问题描述】:
我有一个下拉列表,其中仅包含两个选项 And 和 Or。选择这两个选项时将运行查询,但取决于选择。 When And is selected, a change in the query will be made.我的查询看起来像这样,
$sql =
"SELECT distinct n.node_id, n.path,
n.title_tag as node_name,
n2.title_tag as tree_name,
MATCH (n.title_tag) AGAINST ('%s') as score
FROM nodes n
join trees t on (n.tree_id=t.tree_id and t.status='A' and t.workspace_id=%d)
join nodes n2 on (n2.node_id = t.tree_id)
left join node_links nl1 on (n.node_id=nl1.from_node_id and nl1.to_node_id='%s')
left join node_links nl2 on (n.node_id=nl2.to_node_id and nl2.from_node_id='%s')
WHERE n.node_id!='%s' and nl1.node_link_id is null and nl2.node_link_id is null
HAVING score > 0
ORDER BY score DESC";
注意MATCH AGAINST 部分,这是我想添加And 和Or 条件的地方。如果在选择And 条件时,查询将使用AND 逻辑匹配node_name,并且在选择Or 条件时,查询将使用OR 逻辑匹配node_name,我该怎么做。任何帮助都可以。谢谢。
【问题讨论】:
-
@BillKarwin,老实说,我可以发誓我错过了阅读您提供的链接。我会试试这个,看看这是否有效。非常感谢。
-
@BillKarwin,我将如何投票支持你给你的小费?你能发布你的答案吗?
-
给@diEcho 点赞,花时间展示一个更完整的例子。重要的是给你很好的帮助,我不为积分而受伤! :-)
-
@BillKarwin 另一个快速问题,我将如何确定查询是否有效?我试图回显用于
And和Or的查询,结果相同。我错过了什么吗?
标签: php mysql sql match-against