[英]Empty mysql_query, can't figure it out
I'm having trouble with making this query to work, I have 2 tables one with client info and the other one with product info. 我在使这个查询工作时遇到问题,我有2个表,一个是客户端信息,另一个是产品信息。 Trying to join them while querying the db.
在查询数据库时尝试加入它们。
mysql_query(
"SELECT client.id, client.email, client.prodid, prod.id, prod.name
FROM client, prod
WHERE client.id ="'.mysql_real_escape_string($_GET["id"]).'"
AND client.prodid =prod.id"
);
But that query doesn't return anything. 但该查询不会返回任何内容。 What am I doing wrong?
我究竟做错了什么? Thanks in advance.
提前致谢。
Your quotes are wrong. 你的报价错了。
You use " to start the string in your method. In the middle you use "'.mysql_real_escape_string($_GET["id"]).'"
. Notice that you use "'
instead of '"
. 你使用“在你的方法中启动字符串。在中间你使用
"'.mysql_real_escape_string($_GET["id"]).'"
注意你使用"'
而不是'"
。
This should work better (from a PHP point of view, I did not check your SQL syntax): 这应该更好(从PHP的角度来看,我没有检查你的SQL语法):
mysql_query(
"SELECT client.id, client.email, client.prodid, prod.id, prod.name
FROM client, prod
WHERE client.id ='".mysql_real_escape_string($_GET["id"])."'
AND client.prodid =prod.id"
);
Your quotes appear to be cancelling out the dynamic ID variable. 您的报价似乎取消了动态ID变量。 If your client.id field is numeric, then you should remove the single quotes surrounding mysql_real_escape_string():
如果您的client.id字段是数字,那么您应该删除mysql_real_escape_string()周围的单引号:
mysql_query(
"SELECT client.id, client.email, client.prodid, prod.id, prod.name
FROM client, prod
WHERE client.id = ".mysql_real_escape_string($_GET["id"])." AND client.prodid = prod.id"
);
If it works in PHPMyAdmin then the query's fine. 如果它在PHPMyAdmin中工作,那么查询就可以了。 Enable debugging and use var_dump():
启用调试并使用var_dump():
ini_set('display_errors','on');
error_reporting(E_ALL);
$result = mysql_query($sql_query);
var_dump($result);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.