如果有2个具有相同名称的列,如何在左连接中选择列?[MySQL的]

kra*_*n2g 3 php mysql left-join

我已经LEFT JOIN从我的数据库中获取了2个表中的值.
查询是这样的:

SELECT *
FROM thread
  LEFT JOIN comments ON thread.id_thread = comments.id_thread
WHERE id_type = '1'
ORDER BY data DESC, hour DESC
Run Code Online (Sandbox Code Playgroud)

然后我以这种方式输出值:

<?

while($row = mysqli_fetch_array($query))
{
echo '<div class="col-md-1"></div>';
echo '<div class="col-md-11">';
echo  $row['title'] ."<br><br>".$row['content']."<br><br>";
echo  $row['content_com'];
echo '<div class="col-md-2 pull-right">'. "date: ".$row['data']."<br>"."author: ".'<a href ="/user.php?id='.$row['username'].'">'.$row['username'].'</a>'.'</div>' ."<br><br>";
echo '<form role="form" action="commit.php" method="post"><div class="col-md-offset-1 col-md-9"><input class="form-control" type="text" name="comm"><input type="hidden" name="thread_id" value="'.$row['id_thread'].'"></div></form> <br><br><hr><br>';
echo '</div>';
}

mysqli_close($connect);
?>
Run Code Online (Sandbox Code Playgroud)

然后在commit.php(表单操作)中:

<?php
session_start();

  if(isset($_SESSION['id']))
  {
    $servername = "mysql9.000webhost.com";
    $username = "a5461665_admin";
    $password = "xenovia1";
    $dbname = "a5461665_pap";

    $connect  = mysqli_connect($servername, $username, $password, $dbname);

    $id = (isset($_GET['id'])) ? $_GET['id'] : $_SESSION['id'];

    $ctn = $_POST["comm"];

      $com = mysqli_query($connect,"INSERT INTO comments(content_com,id_thread) values ('".$ctn."', '".$_POST['thread_id']."')");

      header("location:javascript://history.go(-1)");


    if (!$connect) {
        die("Connection failed: " . mysqli_connect_error());
    }

}
else
{
  header(" url=index.php");
}


 ?>
Run Code Online (Sandbox Code Playgroud)

我的问题是隐藏的输入框是id_thread从表中传递给表单操作的字段,comments但是我希望它id_thread从表中传递字段threads,我该怎么做?

Ice*_*man 5

SELECT *, thread.id_thread as mycol
FROM 
thread LEFT JOIN comments 
ON thread.id_thread=comments.id_thread 
WHERE thread.id_type = '1' 
ORDER BY data desc, hour desc
Run Code Online (Sandbox Code Playgroud)

使用表指定列名称并使用别名.因此,SELECT *对于所有列,如前所述,现在采取thread.id_thread和别名mycol.这将是现在可用的mycol,没有更多的名字冲突.