Display username, user and review when there are 2 tables
P粉195200437
P粉195200437 2023-09-09 13:01:47
0
1
673

I'm creating a restaurant review website. In my comments table I have a foreign key called user_id and idk how can I use it to display the username from the users table

My user table My comment form

So my question is how to display the username? What mysql statements do I have to write. I don't know what to do

P粉195200437
P粉195200437

reply all(1)
P粉190883225

Suppose you want to try to get the comment text and username from the corresponding user, you can use a join to combine the information, for example:

SELECT u.username, r.review_text
FROM reviews r
LEFT JOIN users u
ON (u.user_id = r.user_id)

I assume the users table is called users and the reviews table is called reviews, but update those tables as needed, each "aliased" to u and r respectively, and then the table Yes has joined

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!