how to write the mysql query?
table: taxonomy_index
nid tid
2 1
3 1
3 4
3 5
4 6
4 开发者_如何学运维 1
4 3
4 7
table: 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
now i want to according to nid=$nid
get the name
where vid=2
.? how do i do?
the following is my query code. but it's wrong.
$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')
My guess is that you need to replace your single quotes '
with double quotes "
. This is because PHP does not expand variables surrounded by single quotes.
$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")
EDIT:
You also have from
misspelled as form
I think variables in single string quotes are not substitued, therefore try
$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)
精彩评论