表:taxonomy_index
nid tid
2 1
3 1
3 4
3 5
4 6
4 1
4 3
4 7
表:taxonomy_term_data
tid vid name
1 2 java
2 2 php
3 2 c
4 1 tag1
5 1 tag2
6 1 tag3
7 1 tag4
8 1 tag5
现在我想根据 nid=$nid
获取 name
where vid=2
.?我该怎么做?
以下是我的查询代码。但这是错误的。
$result = mysql_query('select tid,name form taxonomy_index as ti left join taxonomy_term_data as ttd on ti.tid=ttd.tid where vid=2 and nid=$nid')
最佳答案
我的猜测是您需要将单引号 '
替换为双引号 "
。这是因为 PHP 不会扩展被单引号包围的变量。
$result = mysql_query("select tid,name from taxonomy_index as ti left join taxonomy_term_data as ttd on ti.tid=ttd.tid where vid=2 and nid=$nid")
编辑:
您还有 from
拼错为 form
关于php - 如何编写mysql查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6166225/