[英]how to write the mysql query?
表: 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
得到vid=2
的name
。? 我該怎么辦?
以下是我的查詢代碼。 但這是錯誤的。
$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
我在堆棧溢出上寫了很多次這個鏈接,它是最好的地方,你可以找到一個教程來幫助你開始使用 mysql,祝你好運
我認為單字符串引號中的變量不會被替換,因此請嘗試
$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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.