Page 1 of 1

INNER JOIN question - getting the username

Posted: Wed Aug 25, 2010 7:45 am
by gluttonous_pet
Hi guys,

I'm trying to get the username out of the user table in accordance to the id in the user table (Which is the same as userid in the blog table). I have the following query so far but I'm not sure how to salvage the username from the users table in order to print it on the page. Could you give me some tips please? Also, is this the best way to do what I'm trying to do?

Code: Select all

$query = "SELECT * FROM blog INNER JOIN user ON blog.userid = 
user.id WHERE userid='1' ORDER BY thetimestamp DESC";

Re: INNER JOIN question - getting the username

Posted: Wed Aug 25, 2010 10:30 am
by AbraCadaver
I'm not sure I understand, but it seems like you want this:

Code: Select all

$query = "SELECT blog.*, user.username FROM blog INNER JOIN user ON blog.userid =
user.id WHERE userid='1' ORDER BY thetimestamp DESC";