Goro
Goro

Reputation: 499

Show only one row from mysql based on usertype

I've made login form where when user log I store in SESSION his credentials. One of the row is usertype which is unique for each user. Now I have two tables. Table users

id
...
usertype

second table is hauses which also has row usertype.

Third table is user_hauses

hause_usertype
user_usertype

Now I've trying when user with usertype=1 log to store this 1 into session and when click on Hauses button to load only that row from DB which is with usertype=1. Tried with this query but didn't work so far.

$q = mysqli_query($con, "SELECT * FROM `houses` AS c
                   LEFT JOIN `user_hauses` AS h2u ON c.hause_id = r2u.user_id
                   LEFT JOIN `users` AS u ON h2u.user_id = u.usertype");

Upvotes: 0

Views: 49

Answers (1)

Robert
Robert

Reputation: 397

looks like a typo, see end of 2nd line change r2u to h2u

$q = mysqli_query($con, "SELECT * FROM `houses` AS c
                   LEFT JOIN `user_hauses` AS h2u ON c.hause_id = h2u.user_id
                   LEFT JOIN `users` AS u ON h2u.user_id = u.usertype");

Upvotes: 3

Related Questions