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).
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.
Comments