How To Display Data With In A Table Format
I want to search the data from mysql and need to display it in a table. Here searching of data is successful but the data is not getting displayed in table, instead it is displayin
Solution 1:
Your $output
is only outputting the data itself. Make it also output an HTML table.
echo '<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>';
while ($row = mysqli_fetch_array($results)) {
echo '
<tr>
<td>'.$row['id'].'</td>
<td>'.$row['name'].'</td>
</tr>';
}
echo '
</table>';
By the way, don't scroll down straight to the code, see the warnings about when/how to use tables as well.
Solution 2:
<?php
include("include/connect.php");
$emp_id = $_POST['emp_id'];
$sqlStr = "SELECT * FROM `employee` ";
//echo $sqlStr . "<br>";
$result = mysql_query($sqlStr);
$count = mysql_num_rows($result);
echo '<table>
<tr>
<th>Employee ID</th>
<th>Name</th>
<th>date of joining</th>
<th>date of living in service</th>
<th>salary</th>
</tr>';
while ($row = mysql_fetch_array($result)) {
echo '
<tr>
<td>'.$row['emp_id'].'</td>
<td>'.$row['name'].'</td>
<td>'.$row['DOJ'].'</td>
<td>'.$row['DLS'].'</td>
<td>'.$row['salary'].'</td>
</tr>';
}
echo '
</table>';
?>
Post a Comment for "How To Display Data With In A Table Format"