【发布时间】:2017-12-18 17:26:47
【问题描述】:
我正在尝试在表格中显示详细信息并在下拉列表中显示值列表。值显示在表中,但下拉列表未显示值,尽管值存在,当我将其保存在会话中并打印时,它出现在顶部。我也有使用选择名称的问题。当我点击按钮并想要读取选项的帖子值时,它给了我错误,如图所示
代码如下:
for($i=0;$i<count($dr_ide);$i=$i+5)
{
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td> <select name='perr' >
<option name='perr' selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option name='perr' value=";
$name ;
echo "> ";
$_SESSION["tt"]=$name;
$name;
echo"</option>";
}
echo "</select></td>";
//echo "<td>" . $dayse[$i] . "</td>";
//echo "<td>" . $timing[$i] . "</td>";
echo "</tr>";
}
}
echo $_SESSION["tt"];
if(isset($_POST['confirm'])){
echo $_POST['perr'];
}
这是我的完整页面代码。
<html>
<head>
<title> Expert System </title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:700,600' rel='stylesheet' type='text/css'>
</head>
<body>
<div >
<table id="cells2" border="0" cellpadding="15" cellspacing="5" font size="6">
<tr>
<th><img id="header2" src="images/Kuwait_University_Logo.jpg" > </th>
<th>KUWAIT UNIVERSITY</th>
</tr>
</table>
<div class='back1'>
<table border='1' align='center' id='customers' >
<?php
require "init.php";
session_start();
global $con,$users,$dr_id,$sub_id,$dr_name,$sub_name,$days,$fav,$timing;
global $dr_ide,$dr_namee,$sub_namee,$dayse,$fave,$timinge;
$query= "SELECT * FROM subjects_current where subjects_current.sub_ID NOT IN (SELECT test.subject_id from test)";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else {
while($row = mysqli_fetch_array($result))
{
$IDs[]=$row['sub_ID'];
$Names[]=$row['Name'];
//echo $row['Name'];
}
}
$query= "SELECT * FROM test order by dr_id";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else { echo "
<tr>
<th>Professor Name</th>
<th>First Choice</th>
<th>Second Choice</th>
<th>Third Choice</th>
<th>Fourth Choice</th>
<th>Fifth Choice</th>
<th>Update Subject</th>
</tr>";
$r=0;
$f=0;
while($row = mysqli_fetch_array($result))
{
$dr_ide[$f]=$row['dr_id'];
$dr_namee[$f]=$row['dr_name'];
$sub_namee[$f]=$row['sub_name'];
$dayse[$f]=$row['days'];
$timinge[$f]=$row['timing'];
$fave[$f]=$row['fav'];
//echo "<tr>";
//echo "<td> Dr. " . $dr_namee[$f] . "</td>";
//echo "<td>" . $sub_namee[$f] . "</td>";
//echo "<td>" . $fave[$f] . "</td>";
//echo "<td>" . $dayse[$f] . "</td>";
//echo "</tr>";
//$r++;
$f++;
}
//for($i=0;$i<count($Names);$i=$i+5)
//{
for($i=0;$i<count($dr_ide);$i=$i+5)
{
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td> <select name='perr' >
<option name='perr' selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option name='perr' value='$name'>$name</option>";
}
echo "</select></td>";
//echo "<td>" . $dayse[$i] . "</td>";
//echo "<td>" . $timing[$i] . "</td>";
echo "</tr>";
}
}
echo $_SESSION["tt"];
if(isset($_POST['confirm'])){
echo $_POST['perr'];
}
?>
</table>
<form method='post' action='edit_subjects.php'>
<input ID="btn2" name="confirm" type="submit" value="Home">
</form>
</div>
</body>
</html>
【问题讨论】:
-
注意:
mysqli的面向对象接口明显不那么冗长,使代码更易于阅读和审核,并且不容易与过时的mysql_query接口混淆。在您对程序风格投入过多之前,值得转换一下。示例:$db = new mysqli(…)和$db->prepare("…")过程化接口是 PHP 4 时代引入mysqliAPI 时的产物,不应在新代码中使用。 -
你是对的,但我只是以这种方式构建了我的所有项目,我有两天的交付时间,所以我无法以其他方式重建它,所以如果你能帮助我完成这项工作,我会的开心