我想从mysql中搜索数据,需要在表格中显示它.在这里搜索数据是成功的,但数据没有显示在表格中,而是以直线显示.这里使用的是$output方法.我的编纂是
form.php的
SearchSeacrh By Name
Name:
search.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'] . " ";
$output .= "name: " . $row['name'] . " ";
$output .= "Telephone: " . $row['Telephone'] . " ";
$output .= "E_mail: " . $row['E_mail'] . " ";
$output .= "visa_category: " . $row['visa_category'] . " ";
$output .= "other_category: " . $row['other_category'] . " ";
$output .= "passport_no: " . $row['passport_no'] . " ";
$output .= "remarks: " . $row['remarks'] . " ";
}
echo $output;
}
else
echo "There was no matching record for the name " . $searchTerm;
?>
如何在html表中显示我的数据.
解决方法:
您的$output仅输出数据本身.使它也输出HTML table.
echo '
ID | Name |
---|
while ($row = mysqli_fetch_array($results)) {
echo '
'.$row['id'].''.$row['name'].'';}
echo '
';顺便说一下,不要直接向下滚动到代码,看看有关何时/如何使用表的警告.
标签:html,php,mysql
来源: https://codeday.me/bug/20191002/1844721.html