Php 如何正确连接两个表中的数据?

Php 如何正确连接两个表中的数据?,php,mysql,Php,Mysql,如何正确连接两个表中的数据? 我的基本结构如下: Table1: clubs - id_club, club_name. Table2: table- id, id_club, games, points, set_win,set_lost. 我已手动将数据添加到数据库中。我已在“表格”表格中输入id_俱乐部,但无法显示俱乐部名称 require_once('conect.php'); $result = $conn->prepare("SELECT * FROM tabele

如何正确连接两个表中的数据? 我的基本结构如下:

Table1: clubs - id_club, club_name.  

Table2: table- id, id_club, games, points, set_win,set_lost. 
我已手动将数据添加到数据库中。我已在“表格”表格中输入id_俱乐部,但无法显示俱乐部名称

require_once('conect.php');
$result = $conn->prepare("SELECT * FROM tabele ORDER BY points DESC, (br_strz - br_str) DESC");
$result->execute();
$results = $result->fetchAll();
foreach ($results as $index => $row)
{
  ?>
  <tr>
    <td><label><?php echo ($index + 1);?>  </label></td>
    <td><label><?php echo $row['club_name']; ?></label></td>
    <td><label><?php echo $row['games']; ?></label></td>
    <td><label><?php echo $row['points']; ?></label></td>
    <td><label><?php echo $row['set_win'];?> : <?php echo $row['set_lost'];?></label></td>
  </tr>
<?php } ?>
require_once('conect.php');
$result=$conn->prepare(“按点描述从选项卡顺序中选择*(br_strz-br_str)描述”);
$result->execute();
$results=$result->fetchAll();
foreach($结果为$索引=>$行)
{
?>
: 

您需要在sql查询中加入表,以便能够访问俱乐部表中的数据。 因此,查询应该类似于

SELECT * FROM table1 INNER JOIN table2 ON table2.id = table1.table2id 

您必须使用club.id加入club\u id才能获得club\u名称。

您可以加入两个表。您可以像这样使用查询:

SELECT `t1`.*, `t2`.*
FROM `Table1` `t1`
   INNER JOIN `Table2` `t2` ON `t1`.`id_club` = `t2`.`id`
ORDER BY `t2`.`points` DESC, (br_strz - br_str) DESC

您可以根据需要使用join

SELECT column_name(s)
FROM table1
JOIN table2 ON table1.column_name = table2.column_name;

欲了解更多信息,请访问:-

您是否尝试过加入它们?规范化您的数据库并使用JOIN非常感谢。请告诉我如何将其与我的PHP代码连接。或者我应该只在哪里将其添加到MyAdmin?我尝试将其添加到SQL部分,然后单击“GO”但它仍然不起作用。我应该在MyAdmin中的哪个部分添加它?