【发布时间】:2017-11-23 11:10:39
【问题描述】:
如何解决?
注意:未定义索引:Ans in C:\wamp64\www\quiz\remove\repeated.php 第 13 行
我的代码:
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;
我的表answer有列名Ans。
其实我想统计students_records中没有值的行数。
例如:
students_records
+----+-----+-----+
| Sr | SRN | ARN |
+----+-----+-----+
| 1 | ge | aj |
| 2 | ge | bd |
+----+-----+-----+
回答
+----+-----+-----+
| Sr | SRN | ARN |
+----+-----+-----+
| 1 | ge | aj |
| 2 | ge | aj |
| 3 | ge | ne |
| 4 | ge | bd |
+----+-----+-----+
这里的计数应该是 1。由于表答案的列ARN 中的值“ne”在students_records 表中ARN 列的行中没有。
【问题讨论】:
-
更改
SELECT *, COUNT(Ans)或COUNT(Ans) as Ans -
@urfusion 如果我写
COUNT(Ans) as Ans它会给我结果,但它计算所有行。但我只想计算表中没有值的行students_records -
@urfusion 我也编辑了问题!
-
问题正在编辑中! @詹斯