5

我在这里做错了什么。我遵循了许多示例,但似乎无法使其正常工作。我有 2 张桌子

表 => 用户

user_id
user_name
user_email
user_password
user_country
user_dobdate
user_company
user_code
user_status
user_type

表 => 应用程序

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 = $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'];

错误信息

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in xxxxxxxxxxxxxxx line 26
4

3 回答 3

5

您的查询;

SELECT users.user_id, app.apply_from 
FROM users 
INNER JOIN applications 
  ON  users.user_id = app.apply_from 
WHERE users.user_code='1'

app...使用table的别名application,但不声明它。

INNER JOIN applications app
于 2013-08-17T11:26:45.607 回答
3

您错过了表的别名,applicationsapp. join尝试以下操作:

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'
于 2013-08-17T11:31:04.960 回答
2

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'
于 2013-08-17T11:25:53.307 回答