Phundament Phundament - 6 months ago 22
MySQL Question

PHP MySQL Select ID from one table and photo from another

I have two tables in my database. One table contains information about users, while the other contains data about reservations. When a user makes a reservation the userid will be placed in the reservation table. Now I would like to show a photo of the user who has made that reservation, along with the remarks and date of the reservation, but the photo is in the users table.

Here are my two tables:


  • Table reservations




reservationID |
userID |
date |
roomtype |
remarks



  • Table users




userID |
userlevel |
email |
password |
foto

Answer

I hope I didn't make any syntax errors in my query but here you go:

SELECT * FROM `users` LEFT JOIN `reservations` ON (`users`.`userID` = `reservations`.`userID`) WHERE users.userID = [userID here]
Comments