我的信息分散在两个数据库中,并希望使用PHP将一些信息放到一个网页上。
mysql_select_db('info',$conn);
mysql_select_db('users',$conn);
$query = "SELECT * FROM `sheet1` WHERE `mtr` = 989";
$result = mysql_query($query);
if (logged_in($user_data['mtr']) === true) {
while($row = mysql_fetch_array($result)) {
echo $row['nr_matricol'] . " " . $row['Numele']. " " . $row['D']. " " . $row['E']. " " . $row['F']. " " . $row['G']. " " . $row['H']. " " . $row['I']. " " . $row['J']. " " . $row['K']. " " . $row['L']. " " . $row['M']. " " . $row['N']. " " . $row['O']. " " . $row['P']. " " . $row['Q']. " " . $row['R']. " " . $row['S']. " " . $row['T']. " " . $row['U']. " " . $row['V']. " " . $row['W'];
echo "<br>";
}
}
我在第一个数据库和第二个数据库中有一个字段mtr
。如何查询这两个数据库以仅向一个用户(当前登录的用户)显示数据?
我知道我必须改变这个
$query = "SELECT * FROM `sheet1` WHERE `mtr` = 989";`
但不知道如何。
答案 0 :(得分:0)
从2个数据库中简单选择:
SELECT *
FROM database_2.table_2
JOIN database_1.table_1
ON (database_2.table_2.some_field = database_1.table_1.some_other_field)
WHERE database_1.table_1.data_1 LIKE database_2.table_2.data_2