0
Hello I would like your help , I am creating a form with php and mysql , in this form has the request screen , type has the fields to be filled with the month and name , on the hill has the month and year and in the name the person enters the name or the number of the card . 
But here comes the problem I’m facing , when the person enters next month the month she requested , but when you do not type comes all the data every month , until there is right because I want it to come like this , but I want the name field stay like this too , when you type the name come only the name and when you don’t type come all , have you to help me .
There’s the part about Query . the $datcadastro is the date this is right but the $nomfuncionario only returns when you type, I want when you do not type anything come all and when you type the name only come the name typed.

public function RetornaRelatorios($datcadastro,$nomfuncionario)
{
    if(!empty($datcadastro)&& !empty($nomfuncionario)){
        $WHERE = "WHERE DATE_FORMAT(a.datcadastro,'%Y-%m') = '$datcadastro' AND (a.nomfuncionario) = '$nomfuncionario' ";
    }else{
        $WHERE = "";
    }
    $this->sql = "SELECT 
                date_format(a.datcadastro,'%d/%m/%Y %H:%i:%s') as datcadastro,
                a.beneficiario,
                a.intercambio,
                a.procedimento,
                date_format(a.datprocedimento,'%d/%m/%Y') as datprocedimento,
                a.numguia,
                a.retrospectivo,
                a.presencial,
                a.nomfuncionario,
                a.audmedico,
                a.hospital
                    FROM opme.auditoria a
                        $WHERE
                ;";
}  
						
To me, it’s duplicate: Search returns equal data and the solution is really quite simple there, but as you want to insist on doing it your way, I leave it up to the community to answer and/or decide whether it is duplicate or not. I just hope that doesn’t start to appear answer that already has in the other, because there is mess.
– Bacco
@Bacco I’ve made your way only one thing I don’t understand what I have to put inside the $WHERE = array();
– allan araujo
It’s not for nothing, you should only touch these lines:
if( !empty( $nome ) ) $condicoes[] = "nome LIKE '$nome'";and repeat for all fields. Each row of these is for a separate field. The rest need not touch, just hit the $query with the table name.– Bacco
Something like this: http://pastebin.com/0K3FugYM
– Bacco
@Bacco worth is working .
– allan araujo
try to understand the logic, you can do really cool things if you understand how it works.
– Bacco