what is NOT working on the code you posted? Are you NOT getting any results? Are you getting the ENTIRE table? Are you getting the WRONG id?
Have you tried to echo your sql statement to verify what sql command is actually being executed?
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
and its being displayed from the user_id of the table rather than getting the result from the id of the table.
I don't understand what you mean. Post a sample of BOTH tables
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
OK, now I see the problem. The issue is that you are executing SELECT * but both tables have an id column. What you need to do is specify precisely which columns you want by prefixing the columns with the table (notice that I used "u" as the alias for the "users" table and "c" for the contacts table):
Assuming you are interested in users.id, try:
$sql='
SELECT c.fname, c.lname, u.id
FROM contacts c INNER JOIN users u ON u.id=c.user_id
WHERE
u.username = "' . mysql_real_escape_string($_SESSION['username']) . '"';
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
FYI: If you REALLY needed BOTH ids, then you could alias one OR both of the ids:
SELECT c.fname, c.lname, u.id as User_id, c.id as Contacts_id...
hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244