i am creating a restaurant review website. in my review table i have a foreign key called user_id and idk how to use it to display the username which is in the user table
so my question is how do i display the username from this? what mysql statement do i have to write. I am lost on what to do
2
Answers
If the relationship between the two tables is mapped out correctly you should be able to run a query to fetch the name of each user. Try to avoid any N+1 query though
Assuming you want to try and get the review text along with the user name from the corresponding user you can use a join to combine the info for example:
I assumed the users table is called
users
and reviews table is calledreviews
but update those as necessary each is "aliased" as u and r respectively and then tables are joined