【发布时间】:2016-08-15 03:52:42
【问题描述】:
我有一个form,人们可以在其中搜索特定用户的数据库。当他们搜索用户并单击提交时,他们会被重定向到不同的页面并显示结果。
我唯一的问题是结果显示在所需的 html 标记之前 - 这是通过 Inspect Element 显示的页面示例:
"Bobby123
"
<!DOCTYPE html>
<html>
<body>
</body>
</html>
如何在所需的 html 标记之后显示结果?如何为要显示的结果设置“设置位置”?
这是我的代码:
<?php
if(isset($_POST['submit'])) {
$term = $_POST['search'];
$searchuser = $stmt = $con->prepare("SELECT * FROM users WHERE username LIKE :term");
$stmt->bindValue(':term', '%'.$term.'%');
$stmt->execute();
if($searchuser->rowCount() > 0) {
while($row = $searchuser->fetch()){
$name = $row['username'];
echo $name;
}
}else{
echo 'No results';
}
}
?>
<form method="post" action="results.php">
<input name="search" type="search">
<input type="submit" name="submit">
</form>
results.php 上的代码就是:
<!DOCTYPE html>
<html>
<body>
</html>
如果可能,我不想使用像 Javascript、Jquery 或任何在客户端运行的代码。
【问题讨论】:
-
如何在没有任何 php 代码的情况下在 results.php 中显示结果?
-
不要回显,存储结果并将它们放在文档中所属的位置。
-
@raptor96
form元素中的action标记在results.php 中显示结果 -
@chris85 我该怎么做?
-
你真的应该发现模板..