php mysql左连接语法错误

时间:2012-09-03 13:55:28

标签: php mysql syntax left-join

你好,我有一些错误,我看不到它,但访问网站的成员,告诉我有错误

$query = mysql_query("
SELECT

m.member_id as member_id,
m.member_group_id as member_group_id,
m.members_display_name as members_display_name,
m.email as email,
m.joined as joined, 
m.member_login_key as member_login_key,
m.msg_count_new as msg_count_new,

p.pp_thumb_photo as pp_thumb_photo,
p.pp_photo_type as pp_photo_type

FROM        ".$forum_prefix."members m
LEFT JOIN   ".$forum_prefix."profile_portal p ON p.pp_member_id = m.member_id

WHERE m.member_id = ".$id."
") or die(mysql_error());

和错误

 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 17

2 个答案:

答案 0 :(得分:0)

$forum_prefix = "table_name";// put table name here.its empty in your code
$id = 2;//put your id here and check
$query = mysql_query("
SELECT

m.member_id as member_id,
m.member_group_id as member_group_id,
m.members_display_name as members_display_name,
m.email as email,
m.joined as joined, 
m.member_login_key as member_login_key,
m.msg_count_new as msg_count_new,

p.pp_thumb_photo as pp_thumb_photo,
p.pp_photo_type as pp_photo_type

FROM        ".$forum_prefix."members m
LEFT JOIN   ".$forum_prefix."profile_portal p ON p.pp_member_id = m.member_id

WHERE m.member_id = ".$id."
") or die(mysql_error());

答案 1 :(得分:0)

  • line 17是查询的最后一行。
  • 这一行中唯一的东西是

    WHERE m.member_id = ".$id."
    
  • 消息错误为““(空字符串)。这是“截断”查询的症状。

因此,错误发生在您的PHP代码中,因为未设置$id var。