0

When I use select indicator...in my select statement below I can't use $row[indicator] when I use select indicator as indicator I can use $row[indicator]. Why is this?

$stmt=$mysqli->prepare("select indicator as indicator, count(status)as 'ok', (select count(status) from viewindicatoren where status ='niet ok' and afdelingid=? group by IND_id ) as 'nietOk' from viewindicatoren where status='ok' and afdelingid=? group by IND_id");
        $stmt->bind_param("ss",$afdelingID,$afdelingID);
        $stmt->execute();

        $res=$stmt->get_result();    
        while ($row=$res->fetch_assoc()){
          echo "indicator: $row[indicator] ok: $row[ok] niet ok: $row[nietOk]";

        }
2
Contributors
4
Replies
13
Views
3 Years
Discussion Span
Last Post by nevek
0

I tryed it with an alias, in this case "indicator", it might as well be "t". The problem is that I have to use an alias for it to work. In other cases I never had to do that.

0

I think you only have to provide an alias for the derived table, no the field 'indicator'. Anyway, ensure that you enclode your fieldnames in backticks.

The status thing is a bit confusing as it looks as though you're storing strings? If so, why not use 0,1 (0 = notOK, 1= OK)?

0

Solved it, apparently it's called Indicator in the db, I thought php looks at the select statement instead of the column name the db returns.
Stupid mistake but I learned something of it.
Thanks for the help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.