skip to Main Content

My goal is return data from my Minecraft server via PHP and MySQL using a table tag

I trying to do this with a while statement, but the table is showing me data outside the limits and some values are not correct and repeated.

I don’t any error messages, but I cannot figure out what is wrong.

<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>

2

Answers


  1. Chosen as BEST ANSWER

    Problem fixed! Since I've got two tables and each one has the same column names, I needed to use "SELECT * FROM luckperms_players l INNER JOIN authme a ON l.username = a.username" I also fixed other CSS problems which were not showing the data correctly! Thank you all so much for the help. Please let me know if my question was well elaborated. If not, suggestions are more than welcome.


  2. is your correct

    $query = "SELECT * FROM luckperms_players, authme";
    

    becuause if you want to check on the base of authme column then you have to add the query in where clause because comma is not used in query and its a type of query error .

    you can do it like

    $query = "SELECT * FROM luckperms_players where authme = 'something' ";
    

    you can also check the documentation here

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search