以下查询成功检查数据库中是否有与用户搜索相等的值($upn
)。
但是在($output
)显示输出时,字符串仅显示$project
和$sum
,但无法显示$fname
和$sname
(对应于数据库中的pupil_forename
和pupil_surname
。
为什么$project
&返回$sum
个值而不是$fname
/ $sname
值?
{$query = mysql_query("SELECT pupil_forename AND pupil_surname from pupil WHERE pupil_id = '$upn'");
$count = mysql_num_rows($query);
if ($count == 0 ) {
$output = "No Pupil exists.";
} else{
while($row = mysql_fetch_array($query)){
$fname = $row['pupil_forename'];
$sname = $row['pupil_surname'];
$sum = ($num1 + $num2 + $num3 + $num4 + $num5 + $num6 + $num7) / 7;
$query = mysql_query("INSERT into test VALUES ('' , '$upn' , '$project' ,'$sum')");
$output = '<div>'.$fname.' '.$sname.' was marked '.$sum.' for their submission of '.$project.'';
}
答案 0 :(得分:0)
你需要说
SELECT pupil_forename, pupil_surname FROM...
说AND
触发布尔检查。它说“这些价值中的每一个都设定了吗?”然后返回单个true / false而不是名称
答案 1 :(得分:0)
尝试
SELECT pupil_forename, pupil_surname FROM pupil WHERE pupil_id = '$upn'
而不是您的查询。