Print a query sql the count (*) in php

0

I have this query prepared in a php file.

$consulta = $conn->prepare("SELECT examen.idexamen,examen.detalles, count(*)
        from examen,preguntas
        having count(*) IN
        (SELECT count(*) FROM preguntas
        group by preguntas.examen)");

And I also want to print the count (*) and I've tried this:

    while($f1 = $consulta->fetch()){
            echo $f1[3];
        }

and it does not work.

Any solution?

    
asked by Borja Sanchez 15.05.2017 в 10:13
source

1 answer

2

In your query there are 3 fields, you are trying to obtain the element of an index that does not exist in the answer of your query. Remember that the first position of the answer array will always start at 0, so:

$f1[0] It will be examen.idexamen

$f1[1] It will be examen.detalles

$f1[2] It will be count(*)

I recommend that when you have a problem with PHP try to look at the error log that is generated on the server because it will always tell you where the error is as well as some clue of it.

    
answered by 15.05.2017 / 10:57
source