-1

How to resolve this?

Notice: Undefined index: Ans in C:\wamp64\www\quiz\remove\repeated.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.

PB Musics
  • 153
  • 2
  • 10

2 Answers2

1

Use like this

$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");
Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33
  • Can you please look at https://stackoverflow.com/questions/47454098/notice-undefined-index-ans-in-c-wamp64-www-quiz-remove-repeated-php-on-line-1#comment81862902_47454098 – PB Musics Nov 23 '17 at 11:18
0

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

urfusion
  • 5,528
  • 5
  • 50
  • 87