左连接中的两个表都有id字段。 试图从第一个数据库中提取id字段,但是获取第二个数据库

左连接中的两个表都有id字段。 试图从第一个数据库中提取id字段,但是获取第二个数据库

问题描述:

Just updated my site from mysql_ to mysqli and broke a previously functioning query.

Im trying to pull the id from spins, as it increments by 1 each time, but I keep getting the player id instead, can someone tell me what Im doing wrong? I tried multiple variations of renaming spins to AS s.spins etc.

$query=$db->query("SELECT * FROM `spins` LEFT JOIN `players` ON `players`.id=`spins`.player ORDER BY `time` DESC LIMIT 30");

Im using the following to call the spin id, but get the players id instead.

  $content.='<td>'.$row['id'].'</td>';

Specifically name the fields in your query, something like :

SELECT `spins`.id as spinsID FROM `spins` LEFT JOIN `players` ON `players`.id=`spins`.player ORDER BY `time` DESC LIMIT 30"

$content.='<td>'.$row['spinsID '].'</td>';