我正在建立一个大学数据库。在管理页面中,我给出了一个选项,如果从下拉菜单中选择了任何程序,将显示在特定程序中注册的所有学生的详细信息。例如,如果用户选择"业务管理"从下拉菜单中按下提交按钮,所有注册业务管理程序的学生的详细信息都会显示在一个表格中。下面是我编写的代码,但它不起作用。
<?php
$con=mysqli_connect("localhost","root","")or die("conection error");
mysqli_select_db($con,"hamdard university")or die("dbase error");
if(isset($_POST['sub']))
{
$p=$_POST['selprog'];
$sql="SELECT * from admission_form where program=$p";
$result=mysqli_query($con, $sql);
echo "<table border=1>
<th>RollNo</th>
<th>First Name</th>
<th>Middle Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Contact</th>
<th>Faculty</th>
<th>Major</th>
<th>Payment</th>";
while($row=mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo "<tr>";
echo "<td>";
echo $row['RollNo'];
echo "</td>";
echo "<td>";
echo $row['firstname'];
echo "</td>";
echo "<td>";
echo $row['middlename'];
echo "</td>";
echo "<td>";
echo $row['lastname'];
echo "</td>";
echo "<td>";
echo $row['address'];
echo "</td>";
echo "<td>";
echo $row['contact'];
echo "</td>";
echo "<td>";
echo $row['major'];
echo "</td>";
echo "<td>";
echo $row['payment'];
echo "</td>";
}
}
?>
<html>
<head>
<title>Admin</title>
</head>
<body>
<h2>Fetch Student Data</h2><br>
<form name="f1" action="" method="POST">
<h3>Data by Program</h3>
Program:<select name="selprog">
<option value="Business Management">Business Managemen</option>
<option value="Liberal Arts">Liberal Arts</option>
<option value="Performing Arts">Performig Arts</option>
<option value="Journalism">Journalism</option>
<option value="Economics">Economics</option>
</select><br>
<input type="submit" value="Fetch Data" name="sub">
</form>
</body>
</html>
答案 0 :(得分:0)
ChildComponents
或者你可以把它变成一个函数并将它放在html代码的中间并摆脱那个echo <?php
$conn = new mysqli('localhost', 'username', 'password', 'database')
or die ('Cannot connect to db');
$result = $conn->query("select id, name from table");
echo "<html>";
echo "<body>";
echo "<select name='id'>";
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['name'];
echo '<option value="'.$id.'">'.$name.'</option>';
}
echo "</select>";
echo "</body>";
echo "</html>";
?>
以及所有