猿问

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

我在模态中有一个表。我希望表格显示足球比赛的前 3 名射手。以下代码不返回表。非常感谢任何帮助!目前我正在尝试在 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>


慕盖茨4494581
浏览 142回答 1
1回答

SMILET

注意到您定义了 $goalsresult 来存储来自您的 mysql_query 调用的结果集,并认为您希望传递它而不是 $result - 除非 $result 是您在其他地方定义并有意使用的内容。这是您的代码示例:$goalsresult = mysqli_query($conn,$topgoals) or die(mysqli_error($conn));if(mysqli_num_rows($goalsresult)>0) {&nbsp; &nbsp; &nbsp;while($row = mysqli_fetch_assoc($goalsresult)){希望这能让你得到你所需要的。
随时随地看视频慕课网APP
我要回答