我有一个带下拉菜单的表单。每当我选择一个程序时,系统都会显示程序分数表。但是当我选择服务名称时,它不会显示服务表。另外,有没有更好,更快,更有效的方法来显示数据库中的表?
这是我的表格:
我得到的错误:
progscores.php
<?php
include'connect.php';
$crit=@$_POST['crit'];
$y2005=@$_POST['y2005'];
$y2006=@$_POST['y2006'];
$y2007=@$_POST['y2007'];
$y2008=@$_POST['y2008'];
$y2009=@$_POST['y2009'];
$y2010=@$_POST['y2010'];
switch($_POST['program'])
{
case 'Computer Science':
$table = 'csprog';
break;
case 'BAED':
$table = 'baedprog';
break;
case 'Psychology':
$table = 'psyprog';
break;
}
$res = mysql_query("SELECT * FROM {$table}");
?>
<html>
<body>
<table width="600" border="1" cellspacing="1">
<tr>
<th>Criteria</th>
<th>2005</th>
<th>2006</th>
<th>2007</th>
<th>2008</th>
<th>2009</th>
<th>2010</th>
</tr>
<?php
while($table=mysql_fetch_assoc($res)){
echo "<tr>";
echo "<td>".$table['crit']."</td>";
echo "<td>".$table['y2005']."</td>";
echo "<td>".$table['y2006']."</td>";
echo "<td>".$table['y2007']."</td>";
echo "<td>".$table['y2008']."</td>";
echo "<td>".$table['y2009']."</td>";
echo "<td>".$table['y2010']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
principal.php
<?php
include 'connect.php';
if($_POST['program']){
include 'progscores.php';
}elseif($_POST['services']){
include 'servscores.php';
}
?>
servscores.php
<?php
include'connect.php';
$scrit=@$_POST['scrit'];
$sy2005=@$_POST['sy2005'];
$sy2006=@$_POST['sy2006'];
$sy2007=@$_POST['sy2007'];
$sy2008=@$_POST['sy2008'];
$sy2009=@$_POST['sy2009'];
$sy2010=@$_POST['sy2010'];
switch($_POST['services'])
{
case 'Library':
$stable = 'library';
break;
case 'Course Administrator':
$stable = 'cadmin';
break;
case 'Front Desk':
$stable = 'frontdesk';
break;
case 'Clubs and Societies':
$stable = 'clubs';
break;
case 'IT Services and Facilities':
$stable = 'itservice';
break;
case 'International Student Office':
$stable = 'stoffice';
break;
}
$res2 = mysql_query("SELECT * FROM {$stable}");
?>
<html>
<body>
<table width="600" border="1" cellspacing="1">
<tr>
<th>Criteria</th>
<th>2005</th>
<th>2006</th>
<th>2007</th>
<th>2008</th>
<th>2009</th>
<th>2010</th>
</tr>
<?php
while($stable=mysql_fetch_assoc($res2)){
echo "<tr>";
echo "<td>".$stable['scrit']."</td>";
echo "<td>".$stable['sy2005']."</td>";
echo "<td>".$stable['sy2006']."</td>";
echo "<td>".$stable['sy2007']."</td>";
echo "<td>".$stable['sy2008']."</td>";
echo "<td>".$stable['sy2009']."</td>";
echo "<td>".$stable['sy2010']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
答案 0 :(得分:2)
$ table未定义,因为您直接将其声明为切换代码块。所以首先你必须声明
$table='';
切换前
因为$ table未定义所以第二个警告出现了