【问题标题】:Notice: Undefined index: Ans in C:\wamp64\www\quiz\remove\repeated.php on line 13注意:未定义索引:第 13 行 C:\wamp64\www\quiz\remove\repeated.php 中的 Ans
【发布时间】: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 列的行中没有。

【问题讨论】:

标签: php mysql


【解决方案1】:

这样使用

$lstmtf = $user_home->runQuery("SELECT COUNT(Ans) as Ans
FROM answer AS a
LEFT JOIN students_records AS s ON a.Sr = s.Sr
WHERE s.Sr IS NULL");

【讨论】:

【解决方案2】:

你可以通过关注得到愿望输出

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

这里正在工作example

【讨论】:

  • 如果我想从答案中删除所有这些行,代码是什么?您能否编辑您的答案并添加更多可用于删除的代码...请求。
  • 你能帮帮我吗?
  • 您想在 1 个查询中执行此操作,还是可以在获得结果后编写另一个查询?
  • 我想删除所有查询,这意味着如果有 5 个,则应该删除所有 5 个!
  • DELETE a FROM answer AS a LEFT JOIN students_records AS s ON a.ARN = s.ARN WHERE s.ARN IS NULL
猜你喜欢
  • 1970-01-01
  • 2018-03-14
  • 2012-12-13
  • 2017-03-12
  • 1970-01-01
  • 2016-04-03
  • 2016-10-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多