Dfrtbx Posted November 19, 2009 Share Posted November 19, 2009 Hello.For a website I'm making, in order to register, you must know someone that is already registered. Checking to make sure that the "referrer" they entered into the registration field is actually a user is easy enough: SELECT firstName, lastName FROM users WHERE firstName = '$refFirstName' && lastName = '$refLastName'; Where $refFirstName and $refLastName are the referrer's first and last names, respectively.Here is the layout of the database.Because it is a "private" site (i.e. a limited user base), I was going to make a page that displays all the users and the person that referred them. Simply put, I have no idea how to do it. In the referrers table, refID is always equal to userID. I cannot figure out a way to get the NAME of a user's referrer out of the database in the same SELECT query as everything else. Would I use a LEFT JOIN or INNER JOIN, or something else? Also, is there anyway to combine the referrer table into the user one? Thanks! Link to comment Share on other sites More sharing options...
alexnofue Posted November 20, 2009 Share Posted November 20, 2009 Hi, you already have the idea, but to get the names of the referrers you need two joinsSELECT *FROM users uINNER JOIN referrers r ON u.refID = r.refIDINNER JOIN users ur ON r.userID = ur.userIDusing the table alias you can call the same table more than one time, then the referres' names could use field alias, something like: ur.firstName AS r_firstName that allows to tell apart the name of the user and the referrer's Link to comment Share on other sites More sharing options...
Dfrtbx Posted November 23, 2009 Author Share Posted November 23, 2009 I see. Thank you! =D Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.