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");

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

3 Years
Discussion Span
Last Post by nevek

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.


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)?


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.