title: Combining MySQL Columns From Different Tables
body: <p>I'm new to this but will explain it as best I can. The goal.... to have a MySQL table which displays the following:</p>
  
  <p><strong>Name | Weapon Used | Victim | Map</strong></p>
  
  <p><em>The problem</em>: The information for this is split between two tables under the same databse.</p>
  
  <p>The "name" of the player is stored in one table but the data of "who killed who" is stored in another via "killerID" and I don't know how to correlate the "killerID" to the "name".</p>
  
  <p>I can get the table to work fine by printing out the information with the killerID #, but I would like to replace that with the person's name. Please see the two attached images:</p>
  
  <p><a href="http://i.imgur.com/jpf7wmX.jpg" rel="nofollow">Table 01</a></p>
  
  <p><a href="http://i.imgur.com/edkhzir.jpg" rel="nofollow">Table 02</a></p>
  
  <p>So <em>instead of having the table show on the website as</em>:</p>
  
  <p>13 | fire_cracker_blast | 7 | c1m2_streets</p>
  
  <p><strong>I would like it to be</strong>:</p>
  
  <p>NeoMaxQ-C | fire_cracker_blast | {YNB} Chatyak | c1m2_streets</p>
  
  <p>The "killerID" is the same as the "playerID" from the other table. Essentially, I want it to understand that killerID = playerID = Print player's name from playerID.</p>
  
  <p>Yes, I have looked for tutorials and got my own tables working - but am struggling with this as I don't know the syntax. I understand that one column from a table must "equal" the other... but am still confused.</p>
  
  <p><strong>EDITS TO SHOW CODE</strong></p>
  
  <pre><code>&lt;?php
  // Make a MySQL Connection
  mysql_connect("URL", "user", "pw") or     die(mysql_error());
  mysql_select_db("DBNAME") or die(mysql_error());
  mysql_set_charset("UTF8");
  // Get specific data from table
  $result = mysql_query("SELECT map,killerID,victimID,weapon
  FROM hlstats_Events_Teamkills
  LEFT JOIN hlstats_PlayerNames
  ON hlstats_Events_Teamkills.killerID=hlstats_PlayerNames.playerID;")
  or die(mysql_error()); 
  
  
  echo "&lt;table class=\"tablesorter-blackice\"&gt;";
  echo "&lt;thead&gt;";
  echo "&lt;tr&gt;&lt;th&gt;Map&lt;/th&gt;&lt;th&gt;Team Killer&lt;/th&gt;&lt;th&gt;Victim&lt;/th&gt;&lt;th&gt;Weapon Used&lt;/th&gt;&lt;/tr&gt;";
  echo "&lt;/thead&gt;";
  echo "&lt;tbody&gt;";
  // keeps getting the next row until there are no more to get
  while($row = mysql_fetch_array( $result )) {
  // Print out the contents of each row into a table
  echo "&lt;tr&gt;&lt;td&gt;"; 
  echo $row['map'];
  echo "&lt;/td&gt;&lt;td&gt;"; 
  echo $row['killerID'];
  echo "&lt;/td&gt;&lt;td&gt;";
  echo $row['victimID'];
  echo "&lt;/td&gt;&lt;td&gt;";
  echo $row['weapon'];
  echo "&lt;/td&gt;&lt;/tr&gt;"; 
  } 
  echo "&lt;/tbody&gt;";
  echo "&lt;/table&gt;";
  ?&gt;
  </code></pre>
  
  <p>Ok, I back tracked a bit... with the current code above... what you see is the second table on this page: <a href="http://chatyak.com/l4d2-mysql.php" rel="nofollow">http://chatyak.com/l4d2-mysql.php</a></p>
  
  <p>I"m confused on the simplicity and how to actually get the combined data to print just the name, instead of the ID. I was trying both responses but perhaps I goofed something up.</p>