mysql - PHP function to compare data in two tables to incorporate in existing script
I need a PHP script that would pull data (player ID) from a mysql table (I know how to do it so far) AND THEN use that player ID (1-5 digit number) to find the corresponding player name in another table.
Basically I need to display which player posted which message on a website.
Here's the script:
<?php
include('mysql_connection.php');
$c = mysqlConnect();
$locale = $_GET['locale'];
$last_bulletins_id = $_GET['bulletins_id'];
sendQuery ("set character_set_results='utf8'");
sendQuery ("set collation_connection='utf8_general_ci'");
if(strcmp($locale,"en") != 0)
$locale = "en";
$result = sendQuery("SELECT * FROM bulletins WHERE id > ".$last_bulletins_id." and locale = '".$locale."' ORDER BY id DESC LIMIT 10");
echo '<table width=\"100%\">';
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo '<tr><td width=\"100%\"><b>Author: </b></td></tr>';
echo '<tr><td width=\"100%\"><b>Date: </b>'.$row[2].'</td></tr>';
echo '<tr><td width=\"100%\">'.nl2br($row[4]).'</td></tr>';
echo '<tr><td width=\"100%\"><hr class="page_speed_1922375399"></td></tr>';
}
echo '</table>';
mysqlClose($c);
?>
However, the message rows do not have the player name. Only his ID. His name is held in another database. So I somehow have to pull the ID, use it to find the corresponding name in another table and display the corresponding name.
What function to use to do this?
Answer
Solution:
If the player name is in the same database and just another table, you can use a join for this
Answer
Solution:
1st DB: FDB ---> table 'user' -- > column 'user_id'
2nd DB: SDB ---> table 'user' -- > column 'user_id, user_name'
Answer
Solution:
Do
JOIN
in your mysql query with the table which ceep player name and Id