karatekid36 Posted July 19, 2007 Share Posted July 19, 2007 In this query: SELECT * FROM prof_ratings WHERE prof_id=$prof_id ORDER BY date_entered DESC; One of the row items pulled is user_id. I have a user table which has a primary key of user_id. In this new query, I would like to have the user name pulled and put into my web page instead of simply displaying the user_id. In the user table, the name is broken into first_name and last_name. How can I pull the user's name with this query so that I can place it in my web page? Thanks Link to comment https://forums.phpfreaks.com/topic/60711-solved-is-a-join-needed/ Share on other sites More sharing options...
anatak Posted July 19, 2007 Share Posted July 19, 2007 yes a join is needed select prof_ratings.* from prof_ratings, user.first_name, user.last_name from prof_ratings JOIN user on user.user_id = prof_ratings.prof_id that will get you the names of all the profs. I am sorry I don't know how to put the where clause in join form since I am struggling with the same problem look here for more information (read the first link in fenways post, reply#3) http://www.phpfreaks.com/forums/index.php/topic,150081.0.html If I figure out how to do the where clause in a join syntax I ll post it here too anatak Link to comment https://forums.phpfreaks.com/topic/60711-solved-is-a-join-needed/#findComment-302049 Share on other sites More sharing options...
DeadEvil Posted July 19, 2007 Share Posted July 19, 2007 SELECT * FROM prof_ratings WHERE prof_id=$prof_id LEFT JOIN user ON prof_id = user_id ORDER BY date_entered DESC; Link to comment https://forums.phpfreaks.com/topic/60711-solved-is-a-join-needed/#findComment-302083 Share on other sites More sharing options...
Barand Posted July 19, 2007 Share Posted July 19, 2007 SELECT p.*, u.firstname, u.lastname FROM prof_ratings p INNER JOIN user u ON p.user_id = u.user_id WHERE p.prof_id = $prof_id ORDER BY p.date_entered DESC; Link to comment https://forums.phpfreaks.com/topic/60711-solved-is-a-join-needed/#findComment-302648 Share on other sites More sharing options...
karatekid36 Posted July 19, 2007 Author Share Posted July 19, 2007 Thank you that is perfect Link to comment https://forums.phpfreaks.com/topic/60711-solved-is-a-join-needed/#findComment-302747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.