dsgffz2579 2015-07-13 21:14
浏览 47
已采纳

使用PDO输出多个用户禁止数据

I am trying to display the current users bans. They do display, but it only outputs 1 detail, when I'm trying to fetchAll data for that current user.

Here is my code

function getPlayerBans($username, $conn) {
        $getPlayerBans = $conn->prepare("SELECT id, player, bannedby, comment, expires, time FROM `bans` WHERE player = :Player");
        $getPlayerBans->bindValue(":Player", $username);
        $getPlayerBans->execute();
        $rows = $getPlayerBans->fetchAll(\PDO::FETCH_ASSOC);
        foreach($rows as $row) {
            $id1 = $row['bannedby'];
            $id2 = $row['comment'];
            $id3 = $row['expires'];

        }
        if($getPlayerBans->rowCount() == 0) 
        {
            echo('No Results Available');
        }else{
        echo "<table id=\"gradient-style\" summary=\"Meeting Results\">
        <thead>
        <tr>
        <th scope=\"col\"><b>Banned By</b></th>
        <th scope=\"col\"><b>Comments</b></th>
        <th scope=\"col\"><b>Expires</b></th>
        <th scope=\"col\"><b>Actions</b></th>
        </tr>
        </thead>
        <tbody>
        <tr>
        <th>$id1</th>
        <th>$id2</th>
        <th>$id3</th>
        <th><img width=\"32px\" height=\"32px\" title=\"Delete\" src=\"/../cp_mod/images/trash_can.png\"></th>
        </tr>
        </tbody>
        </table>";

    }   
} 
  • 写回答

1条回答 默认 最新

  • doujiu6976 2015-07-13 21:19
    关注

    You have to put the foreach loop around the code that prints each row of the table.

    $rows = $getPlayerBans->fetchAll(\PDO::FETCH_ASSOC);
    if (count($rows) == 0) {
        echo('No Results Available');
    } else {
        echo "<table id=\"gradient-style\" summary=\"Meeting Results\">
            <thead>
            <tr>
            <th scope=\"col\"><b>Banned By</b></th>
            <th scope=\"col\"><b>Comments</b></th>
            <th scope=\"col\"><b>Expires</b></th>
            <th scope=\"col\"><b>Actions</b></th>
            </tr>
            </thead>
            <tbody>";
        foreach ($rows as $row) {
            $id1 = $row['bannedby'];
            $id2 = $row['comment'];
            $id3 = $row['expires'];
            echo "<tr>
                    <th>$id1</th>
                    <th>$id2</th>
                    <th>$id3</th>
                    <th><img width=\"32px\" height=\"32px\" title=\"Delete\" src=\"/../cp_mod/images/trash_can.png\"></th>
                </tr>";
        }
        echo "</tbody>
            </table>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器