繁体   English   中英

如何编写 mysql 查询?

[英]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=2name 。? 我该怎么办?

以下是我的查询代码。 但这是错误的。

$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,祝你好运

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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