为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
慕盖茨4494581 2021-08-28 17:10:37
我在模态中有一个表。我希望表格显示足球比赛的前 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>
查看完整描述

1 回答

?
SMILET

TA贡献1796条经验 获得超4个赞

注意到您定义了 $goalsresult 来存储来自您的 mysql_query 调用的结果集,并认为您希望传递它而不是 $result - 除非 $result 是您在其他地方定义并有意使用的内容。


这是您的代码示例:


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


if(mysqli_num_rows($goalsresult)>0) {

     while($row = mysqli_fetch_assoc($goalsresult)){

希望这能让你得到你所需要的。


查看完整回答
反对 回复 2021-08-28
  • 1 回答
  • 0 关注
  • 141 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信