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

时间:2017-11-23 11:10:39

标签: php mysql

如何解决这个问题?

  

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

我的代码:

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;

我的表回复的列名为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 。由于表answer.records中列ARN的行中的值“ne”不在表{student}的列ARN的行中。

2 个答案:

答案 0 :(得分:1)

像这样使用

var result = (
    from auction in db.Auctions
    from best in (from bidder in auction.Bidders
                  from bid in bidder.Bids
                  orderby bid.Amount descending
                  select new { bidder, bid }).Take(1)
    select new
    {
        AuctionId = auction.Id,
        AuctionTitle = auction.Title,
        AuctionStartDate = auction.StartDate,
        ...,
        IdOfTheBestBidder = best.bidder.Id,
        NameOfTheBestBidder = best.bidder.Name,

        IdOfTheBestBid = best.bid.Id,
        AmountOfTheBestBid = best.bid.Amount,
    }).ToList();

答案 1 :(得分:0)

您可以通过以下

获得欲望输出
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