INNER JOIN question - getting the username

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gluttonous_pet
Forum Newbie
Posts: 13
Joined: Thu Aug 19, 2010 4:06 am

INNER JOIN question - getting the username

Post 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";
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: INNER JOIN question - getting the username

Post 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";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply