LEFT JOIN和ALIAS

时间:2017-06-29 22:31:46

标签: mysqli

我有一个类似下面的查询,我遇到了使用别名变量的问题。

我有错误 mysqli_error()预计只有1个参数,0

SELECT
                          msg_id, user_first_name, user_last_name, msg_datetime, msg_mrs, msg_of,
                          msg_telephone, msg_mobile, msg_email, type_description, msg_opt_urgent,
                          msg_opt_confidential, msg_opt_archived, msg_message,

                          for_users.user_first_name AS for_user_fn, 
                          for_users.user_last_name AS for_user_ln, 

                          from_users.user_first_name_fn AS from_user_fn,
                          from_users.user_first_name_ln AS from_user_ln

               FROM
                          messages

               LEFT JOIN
                          users AS for_users ON user_id = msg_for_id

               LEFT JOIN 
                          users AS from_users ON user_id = msg_from_id

               LEFT JOIN
                          message_contact_type ON type_id = msg_contact_type_id

               WHERE
                          msg_id = $msg_id

这里的表格

TBL USERS
user_id
user_first_name
user_last_name

TBL MESSAGES
message_id
message_from_id
message_for_id
message_text

我想得到这些变量

$message_from_fn = $row['from_user_fn'];
$message_from_ln = $row['from_user_ln'];
$message_for_fn = $row['for_user_fn'];
$message_for_ln = $row['for_user_ln'];

0 个答案:

没有答案