5

What am I doing wrong here. I have followed many examples but can't seem to get this working. I have 2 tables

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

$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 Common Sense
  • 156,878
  • 40
  • 214
  • 345
user1772571
  • 73
  • 1
  • 2
  • 8

3 Answers3

5

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.

INNER JOIN applications app
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
3

You have missed the alias name for table applications as 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'
Patrick Kostjens
  • 5,065
  • 6
  • 29
  • 46
Bharathi
  • 539
  • 2
  • 6
  • 18
2

Put abbreviation 'app' for applications table:

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'
user4035
  • 22,508
  • 11
  • 59
  • 94