Reputation: 8240
I am taking up data from a table in xampp database. I am getting all data printed in 2 columns, but somehow, I am getting an extra <td></td> inserted at last in all rows in tbody. Can someone tell me how and where is the problem?
PHP CODE:
if ($result->num_rows > 0) {
// output data of each row
echo "<table class='table table-striped'><thead><tr><th>Name</th><th>Email</th></tr></thead><tbody>";
while($row = $result->fetch_assoc()) {echo "<tr><td>".$row["name"]."</td><td>".$row["email"]."<td></tr>";}
echo "</tbody></table>";
}
Upvotes: 2
Views: 1016
Reputation: 2964
Change this while line:
while($row = $result->fetch_assoc()) {echo "<tr><td>".$row["name"]."</td><td>".$row["email"]."<td></tr>";}
To this:
while($row = $result->fetch_assoc()) {echo "<tr><td>".$row["name"]."</td><td>".$row["email"]."</td></tr>";}
You accidentally put <td>
where you meant to close it with this </td>
Upvotes: 2
Reputation: 861
Take a closer look at <td>".$row["email"]."<td></tr>
you didn't close the td
Make it as follows:
if ($result->num_rows > 0) {
....
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["name"]."</td><td>".$row["email"]."</td></tr>";}
echo "</tbody></table>";
}
Upvotes: 5