Как отображать данные в формате таблицы

Я хочу искать данные из mysql и отображать их в таблице. Здесь поиск данных выполняется успешно, но данные не отображаются в таблице, а отображаются по прямой. Здесь я использую метод $ output. Мои кодировки

form.php

<html dir="ltr" lang="en-US" > <head> <meta charset="UTF-8" /> <title>Search</title> </head> <body> <h1>Seacrh By Name</h1> <form action="search.php" method="get"> <label>Name: <input type="text" name="keyname" /> </label> <input type="submit" value="Search" /> </form> </body> </html> 

search.php

 <?php //capture search term and remove spaces at its both ends if the is any $searchTerm = trim($_GET['keyname']); //check whether the name parsed is empty if($searchTerm == "") { echo "Enter name you are searching for."; exit(); } //database connection info $host = "xx"; //server $db = "xx"; //database name $user = "xx"; //dabases user name $pwd = "xx"; //password //connecting to server and creating link to database $link = mysqli_connect($host, $user, $pwd, $db); //MYSQL search statement $query = "SELECT * FROM customer_details WHERE id LIKE '%$searchTerm%'"; $results = mysqli_query($link, $query); /* check whethere there were matching records in the table by counting the number of results returned */ if(mysqli_num_rows($results) >= 1) { $output = ""; while($row = mysqli_fetch_array($results)) { $output .= "id: " . $row['id'] . "&nbsp;&nbsp;&nbsp;&nbsp;"; $output .= "name: " . $row['name'] . "&nbsp;&nbsp;&nbsp;&nbsp;"; $output .= "Telephone: " . $row['Telephone'] . "&nbsp;&nbsp;&nbsp;&nbsp;"; $output .= "E_mail: " . $row['E_mail'] . "&nbsp;&nbsp;&nbsp;&nbsp;"; $output .= "visa_category: " . $row['visa_category'] . "&nbsp;&nbsp;&nbsp;&nbsp;"; $output .= "other_category: " . $row['other_category'] . "&nbsp;&nbsp;&nbsp;&nbsp;"; $output .= "passport_no: " . $row['passport_no'] . "&nbsp;&nbsp;&nbsp;&nbsp;"; $output .= "remarks: " . $row['remarks'] . "&nbsp;&nbsp;&nbsp;&nbsp;"; } echo $output; } else echo "There was no matching record for the name " . $searchTerm; ?> 

Как я могу отображать свои данные в таблице html.

Ваш $output только данные. Сделайте также вывод HTML-таблицы .

 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>'; 

Кстати, не прокручивайте прямо до кода , см. Предупреждения о том, когда и как использовать таблицы.

 <?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>'; ?> в <?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>'; ?> в <?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>'; ?>