How make a table with php using the echo command with looping data?

ShadowMan

I want to make a nice looking table for my SQL data.

I load in my data like this now:

$sql = "SELECT mednr, mednaam, medvoornaam , medemail, ploeg, medgeslacht FROM Medewerker, Ploeg WHERE medploeg = ploegnummer";

$result = $conn->query($sql);

if ($result->num_rows > 0) {

    // output data of each row
    while($row = $result->fetch_assoc()) {
        if ($row["ploeg"] == "Tapper") {
        echo 
    "<td class='link2'>" . $row["mednaam"] . "</td>".
    "<td class='link2'>" . $row["medvoornaam"] . "</td>".
    "<td class='link2'>" . $row["medemail"] . "</td>".
    "<td class='link2'>" . $row["ploeg"] . "</td>".
    "<td class='link2'>" . $row["medgeslacht"] . "</td>".

        '<form id="delete" method="post" action="">'.
        '<input type="hidden" name="delete_rec_id" value="<?php print $id; ?>"/>'.
        '<input type="submit" name="delete" value="Delete"/>'."</form>".
    "</br>"."</hr>";
            ;
    }
    }
} else {
    echo "0 results";
}

But I want to make a nice looking table. The problem is that the echo keeps looping the data so I cant make <table> and <td> tags because it will create a table and td for each piece of data.

I know from jQuery were I could use $append to put the data inside a certain tag.

Is there any way I could do this with PHP?

(I'm very new to PHP and programming in general so please excuse me for this simple question).

ShadowMan

Oke this is how I got it to work, by ending the php code when I wanted to creat a table.

Thank you for your help!

    $sql = "SELECT mednr, mednaam, medvoornaam , medemail, ploeg, medgeslacht FROM Medewerker, Ploeg WHERE medploeg = ploegnummer";

$result = $conn->query($sql);
?> <table id='table2'> <tbody><?php
if ($result->num_rows > 0) {
    // Table header -->
        echo "<thead>".
            "<tr>".
                '<th scope="col" id="...">This is the table header</th>'.

            "</tr>".
        "</thead>";

    // output data of each row
    while($row = $result->fetch_assoc()) {
        if ($row["ploeg"] == "Tapper") {
        echo "<tr>";
        echo "<td class='link2'>" . $row["mednaam"] . "</td>";
        echo "<td class='link2'>" . $row["medvoornaam"] . "</td>";
        echo "<td class='link2'>" . $row["medemail"] . "</td>";
        echo "<td class='link2'>" . $row["ploeg"] . "</td>";
        echo "<td class='link2'>" . $row["medgeslacht"] . "</td>";
            echo "</br>"."</hr>";
        echo "</tr>";
    }
    }
    ?></tbody></table><?php
} else {
    echo "0 results";
}
?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How make a table with php using the echo command with looping data?

From Dev

Echo a table in PHP array looping

From Dev

Make Looping Table PHP

From Dev

How to echo data into 3 columns in a table in php?

From Dev

How to make inside html table in php echo a normal contest

From Dev

How to echo <tr> using php and ajax to appear inside <table> </table>

From Dev

how to make echo PHP link

From Dev

How to echo an image using PHP inside an HTML table

From Dev

How to update table while looping the select command?

From Dev

how to style php echo table

From Dev

Echo json data in php for data table use

From Dev

Echo json data in php for data table use

From Dev

how to echo command (make a file) - batch file

From Dev

how to make table using php foreign key

From Dev

How to select and echo MySQL data (one to many) using PHP

From Dev

PHP + MYSQL - Looping Through Table Data Based

From Dev

How to make echo results in table hyperlinks

From Dev

How to make echo table with two div tag?

From Dev

How to make php echo a sub section of an array

From Dev

How to print #!/bin/bash using echo command

From Dev

No echo for form data using GET method in PHP

From Dev

How to display PHP echo in a HTML table?

From Dev

how to echo a hyperlink in a html table via php

From Java

How to show data in a table by using psql command line interface?

From Dev

How to delete/truncate the data in the table using command line in big query?

From Dev

How to echo all video ids using php youtube data api php

From Dev

PHP Echo with System Command

From Dev

How to make curl command into php?

From Dev

How to make a batch file containing >nul on echo command

Related Related

HotTag

Archive