【发布时间】:2019-02-12 05:00:04
【问题描述】:
所以我有一个使用 HTML、PHP 和 mysql 的脚本,我想在某些情况下显示一个按钮。 这是我的脚本:
<?php
include_once('dbconnect.php');
$q = $_POST['q'];
$q = $_GET['query'];
$query = mysqli_query($conn,"SELECT * FROM `Persons` WHERE `id` LIKE '%$q%'");
$count = mysqli_num_rows($query);
if($count != "1"){
$output = '<h2>No result found!</h2>';
}else{
while($row = mysqli_fetch_array($query)){
$s = $row['name'];
$output .= '<h2>Found: '.$s.'</h2><br>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
</head>
<body>
<form method="POST" action="index.html">
<input type="submit" name="return" value="Return">
</form>
<?php echo $output; ?>
</body>
</html>
具体来说,我只想在输出为“未找到结果”时显示返回按钮,当 SQL 数据库中与给定查询匹配的行数不是 1 时。我该怎么做呢?我对 PHP 和 mySQLi 比较陌生,但是从我的研究中我无法弄清楚如何完成这样的任务,有什么想法吗?
【问题讨论】:
-
通过使用简单的 php
if语句,您可以在上面代码的 html 位中的<?php ?>中执行此操作。