Displaying data in table format from mysql database with php loop

Mena

Need to display retrieved data from mysql table in table format, but not getting the right display i planned for. This is how i want it to look like Target display

But this is what am getting based on my code Current display

This is the html code

<div>
        <table class="table table-striped table-hover">
            <thead>
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Department</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>

                <?php
                    $staff_set = find_all_employee();
                    while ($staff = mysqli_fetch_assoc($staff_set)) {
                        //display staff first name, last name, department and action (edit and delete links)
                ?>
                <tr>
                    <td>
                        <?php
                            echo $staff["first_name"];
                            }
                        ?>
                    </td>

                    <?php 
                        $staff_set = find_all_employee();
                        while ($staff = mysqli_fetch_assoc($staff_set)) {
                            //display staff last name
                    ?>
                    <td>
                        <?php
                            echo $staff["last_name"];
                            }
                        ?>
                    </td>

                    <?php 
                        $staff_set = find_all_employee();
                        while ($staff = mysqli_fetch_assoc($staff_set)) {
                            //display staff department
                    ?>
                    <td>
                        <?php
                            echo $staff["department"];
                            }
                        ?>
                    </td>

                    <td>
                        <a href="edit_admin.php"><span class="glyphicon glyphicon-pencil"> Edit</span></a> 
                        &nbsp 
                        <a href=""><span class="glyphicon glyphicon-trash"> Delete</span></a>
                    </td>
                </tr>

            </tbody>
        </table>
    </div>

Here is the function that am using to find the list of all employee from the my staff table

function find_all_employee() {
    global $connection;

    $query  = "select * from staff";
    $staff_set = mysqli_query($connection, $query);
    confirm_query($staff_set);
    return $staff_set;
}

Is there a better way to write the loop and display my data in the right way? I have looked up similar threads but still not able to grasp.

Standej

I dont understand why you calling so much tie function and also why making so much loops. Let me try fi your code:

<div>
    <table class="table table-striped table-hover">
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Department</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>   
        <?php
            $staff_set = find_all_employee();
            while ($staff = mysqli_fetch_assoc($staff_set)) {
                 //display staff first name, last name, department and action (edit and delete links)
        ?>
            <tr>
                <td>
                    <?php echo $staff["first_name"]; ?>
                </td>            
                <td>
                    <?php echo $staff["last_name"]; ?>
                </td>
                <td>
                    <?php echo $staff["department"]; ?>
                </td>
                <td>
                    <a href="edit_admin.php"><span class="glyphicon glyphicon-pencil"> Edit</span></a> 
                        &nbsp 
                    <a href=""><span class="glyphicon glyphicon-trash"> Delete</span></a>
                </td>
            </tr>
        <?php
        }
        ?>
        </tbody>
    </table>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

mysql data not displaying in table format

From Dev

Displaying results from mysql database in a html/php table

From Dev

Displaying results from mysql database in a html/php table

From Dev

decoding json from mysql database and displaying it on a table php

From Dev

Displaying data from mysql database

From Dev

Fetching data from MySQL database using PHP, Displaying it in a form for editing

From Dev

How do I write a PHP loop to display data from a database query in Table format?

From Dev

PHP MYSQL Displaying the same data from table to another page

From Dev

PHP: Show data from mysql database in table

From Dev

Date format from MySQL on table displaying incorrectly

From Dev

Date from mysql database is not displaying in html table using the date_format() function

From Dev

php ,mysql image is not displaying from database

From Dev

Displaying Categories and Subcategories in PHP from MySQL database

From Dev

Php code not displaying the data right from database

From Dev

HTML in PHP - displaying variables from MYSQL table

From Dev

ChartJS - format datetime X axis when displaying data from MySql table

From Dev

displaying mysql database in php

From Dev

Displaying ALL data from sql table in PHP?

From Dev

Get data from mysql database inside for loop with php pdo

From Dev

Display data from mysql query in table format php

From Dev

Retrieving and displaying data from MySql in PhP

From Dev

PHP Echo not displaying data from MySql

From Dev

PHP select one data from mysql NOT DISPLAYING

From Dev

displaying data from MySQL in PHP according to a condition

From Dev

Retrieve data from mysql database and insert it in a table using php

From Dev

php code to retrieve data from mysql database and display in html table

From Dev

Joining two tables in PHP/MySQL and displaying elements from both when data from one table is null and the other table's data is not

From Dev

Displaying a table from MySQL database onto webpage with Ruby Sinatra

From Dev

Format date from database to table using php

Related Related

  1. 1

    mysql data not displaying in table format

  2. 2

    Displaying results from mysql database in a html/php table

  3. 3

    Displaying results from mysql database in a html/php table

  4. 4

    decoding json from mysql database and displaying it on a table php

  5. 5

    Displaying data from mysql database

  6. 6

    Fetching data from MySQL database using PHP, Displaying it in a form for editing

  7. 7

    How do I write a PHP loop to display data from a database query in Table format?

  8. 8

    PHP MYSQL Displaying the same data from table to another page

  9. 9

    PHP: Show data from mysql database in table

  10. 10

    Date format from MySQL on table displaying incorrectly

  11. 11

    Date from mysql database is not displaying in html table using the date_format() function

  12. 12

    php ,mysql image is not displaying from database

  13. 13

    Displaying Categories and Subcategories in PHP from MySQL database

  14. 14

    Php code not displaying the data right from database

  15. 15

    HTML in PHP - displaying variables from MYSQL table

  16. 16

    ChartJS - format datetime X axis when displaying data from MySql table

  17. 17

    displaying mysql database in php

  18. 18

    Displaying ALL data from sql table in PHP?

  19. 19

    Get data from mysql database inside for loop with php pdo

  20. 20

    Display data from mysql query in table format php

  21. 21

    Retrieving and displaying data from MySql in PhP

  22. 22

    PHP Echo not displaying data from MySql

  23. 23

    PHP select one data from mysql NOT DISPLAYING

  24. 24

    displaying data from MySQL in PHP according to a condition

  25. 25

    Retrieve data from mysql database and insert it in a table using php

  26. 26

    php code to retrieve data from mysql database and display in html table

  27. 27

    Joining two tables in PHP/MySQL and displaying elements from both when data from one table is null and the other table's data is not

  28. 28

    Displaying a table from MySQL database onto webpage with Ruby Sinatra

  29. 29

    Format date from database to table using php

HotTag

Archive