简体   繁体   中英

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 wrote this link on stack overflow so many times and it is the best place where you can find a tutorial to help you get started with mysql, good luck

Php: Database and Other animals

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM