我需要从下拉列表中获取值并将其查询到其他SQL命令以将最终数据提取到表中。我有这个代码,但单击提交按钮时表中没有显示任何内容。实际上,表格消失了,没有显示任何内容。
<?php
require_once('../include/global.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div class="">
<form action="" method="submit">
<select name="Date" required class="form-control" id="Date">
<option value="">Please Select Date</option>
<?php $sql2="SELECT * FROM clinic.appoint GROUP BY date";
$result2 = mysqli_query($con, $sql2) or die($sql2."<br/><br/>".mysql_error());
while($rows2=mysqli_fetch_array($result2)){?>
<option value="<?php echo $rows2['date'] ?>"><?php echo $rows2['date'] ?></option>
<?php } ?>
</select>
<input type="submit" name="submit" value="Select Date" />
</form>
<?php
if(isset($_POST['submit'])){
if(isset($_POST['Date'])){
$selectOpt =$_REQUEST['Date'];
$sql="SELECT * FROM clinic.appoint WHERE date='".$selectOpt."' ";
$result = mysqli_query($con, $sql) or die($sql."<br/><br/>".mysql_error());
$rows=mysqli_fetch_array($result);
}
else{
$sql."<br/><br/>".mysql_error();
}
?>
<table>
<th>Time</th>
<th>Name</th>
<tr>
<td><?php echo $rows['time'] ?></td>
<td><?php echo $rows['name'] ?></td>
</tr>
</table>
<?php } ?>
</div>
</body>
</html>
答案 0 :(得分:1)
只需在页面上复制并粘贴完整代码并更改数据库信息
即可我认为这对你有用
Dicon