如何在php中在表中显示sql中的每一行

如何在php中在表中显示sql中的每一行,php,sql,Php,Sql,我在一个房间里有一张桌子。我想让这张桌子展示一场足球赛中排名前三的射手。以下代码未返回该表。非常感谢任何帮助!。目前,我正在尝试在php标记中回显表,但我不确定这是否是最好的方法,我采用了这种方法,因为我希望从数据库返回三行 <div class="modal fade bd-example-modal-lg" id="homeleaderboard" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-

我在一个房间里有一张桌子。我想让这张桌子展示一场足球赛中排名前三的射手。以下代码未返回该表。非常感谢任何帮助!。目前,我正在尝试在php标记中回显表,但我不确定这是否是最好的方法,我采用了这种方法,因为我希望从数据库返回三行

<div class="modal fade bd-example-modal-lg" id="homeleaderboard" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">

  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <h3 style="text-align: center;">Most Goals</h3>


      <?php
      $topgoals="SELECT player,panel.name,count(*) AS goalcount FROM fixtures
      inner join panel
      on fixtures.player=panel.id
      where fixture='$fixture_id' and goal='1'
      group by player
      order by goalcount desc
      limit 3";

      $goalsresult=mysqli_query($conn,$topgoals) or die(mysqli_error($conn));

      if(mysqli_num_rows($result)>0){
        while($row=mysqli_fetch_assoc($result)){
          $goalnames=$row['name'];
          $goaltotal=$row['goalcount'];
          echo "<div class='table-responsive'>
                <table class='table table-striped table-bordered'>
                <thead>
                <tr>
                <th>Player</th>
                <th>Goals</th>
                </tr>
                </thead>
                <tr>
                <td>$goalnames</td>
                <th>$goaltotal</th>


                </tr>
                </table>
                </div>

                  ";
      }
        }

       ?>

  </div>
</div>
</div>
         </div>

大多数目标

注意,您定义了$goalsresult来存储mysql_查询调用的结果集,并认为您希望传递该结果而不是$result,除非$result是您在其他地方定义的并且有意使用的

下面是一个代码示例:

$goalsresult = mysqli_query($conn,$topgoals) or die(mysqli_error($conn));

if(mysqli_num_rows($goalsresult)>0) {
     while($row = mysqli_fetch_assoc($goalsresult)){

希望这能满足您的需要。

什么是
$result
?当您让它工作时,您需要稍微调整一下HTML。您正在为每一行输出整个表。(除非您打算这样做。)如果您只需要一个表,则需要在while循环之前输出开头的
标记和所有的
内容,然后输出结尾的
标记。嗨,我所有的错误$result应该是$goalresult。谢谢你的支持help@Don谢谢你的帮助!我的目的是让所有的球员和他们的价值观在同一张桌子上。你能提个建议吗