If I'm reading this correctly, this is a MySQL question - PHP's mysqli and PDO extensions will try to run whatever query you pass to them. So, it sounds like what you're asking about are MySQL JOINS. Assuming your database is set up correctly (normalized), your example is a very simple one. Let's take the table structure below:
Posts Users
|-----------------|-----------------|
| PostID | UserID |
| UserID | Name |
|-----------------|-----------------|
(Sorry about the display, but hopefully you get the idea).
Note that you've got UserID in both tables - in the Users table, it's the primary key. It's the foreign key in Posts. With this set up, you can use this query to get the post ID and user name:
SELECT u.Name
,u.UserID
,p.PostID
FROM Posts p
LEFT JOIN Users u
ON p.UserID = u.UserID
While I'm at it, let me recommend using PDO instead of MySQLi - it's a much more user-friendly system, especially when dealing with prepared statements and variable binding (which you should be using if you're not already).