使用JOIN从ID显示用户名

I am trying to use a JOIN to connect the "user_id" from my "users" table, with my "topic_by" in my "topics" table, I searched around and set up the following code.

$sql = "SELECT topics.topic_id, topics.topic_subject, topics.topic_date, topics.topic_cat, topics.topic_by
            FROM topics 
            INNER JOIN users ON topics.topic_by=users.user_id
            WHERE topics.topic_cat = " . mysql_real_escape_string($_GET['id']) . " ORDER BY topics.topic_date DESC;";

It's not returning any errors, but when I try to call the user_name..

. $row['users.user_name'] .

There is just a blank space where the data should be, what am I doing wrong? Thanks.

You didn't select the user_name column in your SELECT statement.

Try this:

$sql = "SELECT topics.topic_id, topics.topic_subject, topics.topic_date, topics.topic_cat, topics.topic_by, users.user_name
  FROM topics 
  INNER JOIN users ON topics.topic_by=users.user_id
  WHERE topics.topic_cat = " . mysql_real_escape_string($_GET['id']) . " ORDER BY topics.topic_date DESC;";

To select this column data in your $row array, you would write it like: $row['user_name']. The keys in your $row array are the column names (or aliases, if provided) but do not include the table name.