我的实时搜索工作得很好,但是我的标签不在td中。我不知道出了什么问题。图片和代码如下。提前谢谢你。问题在td中,标签。
enter code here
<?php
@include('./config/constants.php');
$output = '';
if (isset($_POST['query'])) {
$search = $_POST['query'];
$stmt = $conn->prepare("SELECT * FROM clients WHERE full_name LIKE CONCAT('%',?,'%') OR email LIKE CONCAT('%',?,'%')");
$stmt->bind_param("ss", $search, $search);
} else {
$stmt = $conn->prepare("SELECT * FROM clients");
}
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$output = "<tr>
<th>ID</th>
<th>Full Name</th>
<th>E-mail</th>
<th>Phone</th>
<th>City</th>
<th>Address</th>
<th>Actions</th>
</tr>
";
while ($row = $result->fetch_assoc()) {
$output .= "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['full_name'] . "</td>
<td>" . $row['email'] . "</td>
<td>" . $row['phone'] . "</td>
<td>" . $row['city'] . "</td>
<td>" . $row['address'] . "</td>
<td>"
?>
<a href="<?php echo SITEURL; ?>/update-client.php?id=<?php echo $row['id']; ?>" class="main-btn">Update Client</a>
<a href="<?php echo SITEURL; ?>/delete-client.php?id=<?php echo $row['id']; ?>" class="danger-btn">Delete Client</a>
<?php
"</td>
</tr>";
}
echo $output;
} else {
echo "<h3>No Records found!</h3>";
}
在表行之前输出链接。
您直接输出它们,然后在变量$output
中输出行
删除while循环中的?>
和<?php
标记,并将按钮作为$output
字符串的一部分
while ($row = $result->fetch_assoc()) {
$output .= "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['full_name'] . "</td>
<td>" . $row['email'] . "</td>
<td>" . $row['phone'] . "</td>
<td>" . $row['city'] . "</td>
<td>" . $row['address'] . "</td>
<td>" . '<a href="'.SITEURL.'/update-client.php?id='.$row['id'].'" class="main-btn">Update Client</a>'.
'<a href="'.SITEURL.'/delete-client.php?id='.$row['id'];.'" class="danger-btn">Delete Client</a>'.
."</td>
</tr>";
}