[英]MySQLI Inner Join 2 Tables
What am I doing wrong here.我在这里做错了什么。 I have followed many examples but can't seem to get this working.
我已经遵循了许多示例,但似乎无法使其正常工作。 I have 2 tables
我有2张桌子
Table => users表 => 用户
user_id
user_name
user_email
user_password
user_country
user_dobdate
user_company
user_code
user_status
user_type
Table => applications表 => 应用程序
apply_id
apply_from
apply_leave_type
apply_priority
apply_start_date
apply_end_date
apply_halfday
apply_contact
apply_reason
apply_status
apply_comment
apply_dated
apply_action_date
SQLI QUERY SQLI查询
$query = $db->select("SELECT users.user_id, app.apply_from FROM users INNER JOIN applications ON users.user_id = app.apply_from WHERE users.user_code='1'");
$rows = $db->rows();
foreach ($rows as $apply){
$apply_id = $apply['apply_id'];
$apply_from = $apply['apply_from'];
Error Message错误信息
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in xxxxxxxxxxxxxxx line 26
Your query;您的查询;
SELECT users.user_id, app.apply_from
FROM users
INNER JOIN applications
ON users.user_id = app.apply_from
WHERE users.user_code='1'
...uses an alias app
for the table application
, but does not declare it. ...为表
application
使用别名app
,但不声明它。
INNER JOIN applications app
You have missed the alias name for table applications
as app
in join
.您错过了表
applications
的别名作为app
in join
。 Try the following:请尝试以下操作:
SELECT users.user_id,app.apply_from
FROM users
INNER JOIN applications app ON users.user_id = app.apply_from
WHERE users.user_code='1'
Put abbreviation 'app' for applications
table:为
applications
表添加缩写“app”:
SELECT
users.user_id,
app.apply_from
FROM
users
INNER JOIN
applications AS app
ON
users.user_id = app.apply_from
WHERE
users.user_code='1'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.