首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP表不正确地显示mysql数据

PHP表不正确地显示mysql数据
EN

Stack Overflow用户
提问于 2022-09-28 21:26:32
回答 2查看 73关注 0票数 0

我的目标是使用一个表标记,通过PHP和MySQL从我的Min克拉夫特服务器返回数据。

我试图用while语句来实现这一点,但是表显示的数据超出了限制范围,有些值是不正确的,而且是重复的。

我没有任何错误信息,但我不知道哪里出了问题。

代码语言:javascript
复制
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
                <thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
                    <tr>
                        <th scope="col" class="py-3 px-6">
                            Identidade
                        </th>
                        <th scope="col" class="py-3 px-6">
                            Rank
                        </th>
                        <th scope="col" class="py-3 px-6">
                            Estado
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600">
                        <th scope="row" class="flex items-center py-4 px-6 text-gray-900 whitespace-nowrap dark:text-white">
                            <?php
                            include_once 'config.php';
                            if ($conn->connect_error) {
                                die("ERRO:" . $conn->connect_error);
                            }

                            $sql = "SELECT * FROM luckperms_players";
                            $result = $conn->query($sql);

                            if ($result->num_rows > 0) {
                                while ($row = $result->fetch_assoc()) {
                                    echo "<tr>";
                                    echo "<td><img class='w-10 h-10 rounded-full' src='https://cravatar.eu/helmhead/" . $row['username'] . "/190.png' />";
                                    echo "<div class='pl-3'><div class='text-base font-semibold'>" . $row['username'] . "</div><div class='font-normal text-gray-500'>" . $row['uuid'] . "</div></div></td>";
                                    echo "<td class='py-4 px-6 capitalize'>" . $row['primary_group'] . "</td>";
                                    echo "<td class='py-4 px-6'> <div class='flex items-center'> <div class='h-2.5 w-2.5 rounded-full bg-green-400 mr-2'></div>" . $row['realname'] . "</div></td>";
                                    echo "</tr>";
                                };
                            } else {
                                echo "Sem dados!";
                            }
                            $conn->close();
                            ?>
                    </tr>
                </tbody>
            </table>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-10-02 17:52:11

问题解决了!因为我有两个表,每个表都有相同的列名,所以我需要使用"SELECT * FROM luckperms_players l INNER JOIN authme a ON l.username = a.username“--我还修复了其他没有正确显示数据的CSS问题!非常感谢你们的帮助。请告诉我,我的问题是否得到了很好的阐述。如果不是,建议是非常受欢迎的。

票数 0
EN

Stack Overflow用户

发布于 2022-09-28 21:53:37

你是对的

代码语言:javascript
复制
$query = "SELECT * FROM luckperms_players, authme";

因为如果您想要在authme列的基础上进行检查,那么必须在where子句中添加查询,因为逗号不在查询中使用,而且它是查询错误的一种类型。

你可以这样做

代码语言:javascript
复制
$query = "SELECT * FROM luckperms_players where authme = 'something' ";

您也可以在这里查看文档。

https://dev.mysql.com/doc/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73887955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档