为什么不显示查询结果?

时间:2014-01-04 14:26:06

标签: php mysql

以下查询成功检查数据库中是否有与用户搜索相等的值($upn)。

但是在($output)显示输出时,字符串仅显示$project$sum,但无法显示$fname$sname(对应于数据库中的pupil_forenamepupil_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.'';
    }

2 个答案:

答案 0 :(得分:0)

你需要说

SELECT pupil_forename, pupil_surname FROM...

AND触发布尔检查。它说“这些价值中的每一个都设定了吗?”然后返回单个true / false而不是名称

答案 1 :(得分:0)

尝试

SELECT pupil_forename, pupil_surname FROM pupil WHERE pupil_id = '$upn'

而不是您的查询。