user2520162 user2520162 - 10 months ago 51
HTML Question

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 displaying in a straight line. Here am using $output method. My codings are


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



//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.";

//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;
echo "There was no matching record for the name " . $searchTerm;

How can i display my data's in html table.


Your $output is only outputting the data itself. Make it also output an HTML table.

echo '<table>

while ($row = mysqli_fetch_array($results)) {
    echo '


echo '

By the way, don't scroll down straight to the code, see the warnings about when/how to use tables as well.