douqianke7467 2017-11-23 11:10
浏览 164
已采纳

注意:未定义的索引:第13行的C:\ wamp64 \ www \ quiz emove epeated.php中的Ans

How to resolve this?

Notice: Undefined index: Ans in C:\wamp64\www\quizemoveepeated.php on line 13

My code:

require_once '../class.user.php';
$user_home = new USER();
$lstmtf = $user_home->runQuery("SELECT COUNT(Ans)
FROM answer AS a
LEFT JOIN students_records AS s ON a.Sr = s.Sr
WHERE s.Sr IS NULL");
    $lstmtf->execute();
$reg_rst = $lstmtf->fetch(PDO::FETCH_ASSOC);
$registered= $reg_rst['Ans'];
        echo $registered;

My table answer has column name Ans.

Actually, I want to count the numbers of rows which do not have values in students_records.

For Eg:

students_records

+----+-----+-----+ 
| Sr | SRN | ARN |
+----+-----+-----+
| 1  | ge  | aj  |
| 2  | ge  | bd  |
+----+-----+-----+  

answer

+----+-----+-----+
| Sr | SRN | ARN |
+----+-----+-----+
| 1  | ge  | aj  |
| 2  | ge  | aj  |
| 3  | ge  | ne  |
| 4  | ge  | bd  |
+----+-----+-----+ 

Here count should be 1. As the value "ne" in column ARN of table answer is no where in the rows of column ARN in table students_records.

  • 写回答

2条回答 默认 最新

  • 普通网友 2017-11-23 12:08
    关注

    You can get the desire output by following

    SELECT count(a.Ans) as ans
    FROM answer AS a
    LEFT JOIN students_records AS s ON a.ARN = s.ARN
    WHERE   s.ARN IS NULL
    

    Here is working example

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化