PHP and Javascript - Adjusting Mysql Table Search (Doctrine Query)

Asked

Viewed 78 times

0

I’m doing on my client page, which I took over from another developer, a section to search for events registered in the Mysql database. How is that page:

<div id="detalhesBusca" class="textDescricaoSobre font13" style="display: none">
    <b>BUSCA DE EVENTO</b><br><br>
    <div class="BoxForm1"><span class="titNomeInputs"><b>Digite o número do evento:</b></span>
        <div class="inputMGM">
            <input name="buscaNumero" id="buscaNumero" class="validate[required]" title=""></input>
        </div>
        <input id="buscaNoBanco" name="buscaNoBanco" type="button" class="textDescricaoSobre font13" value="Buscar Evento" onclick="buscaBanco(document.getElementById('buscaNumero').value);" style="cursor: pointer; width: 93px;" />
    </div>
    <div id="resultadoBusca" class="textDescricaoSobre font13" style="display: none">
        <b>RESULTADO DA BUSCA</b><br><br>
        <i>Código:</i> <label id="resultCodigo"></label><br>
        <i>Modelo:</i> <label id="resultModelo"></label><br>
        <i>Evento:</i> <label id="resultEvento"></label><br>
        <i>Local:</i> <label id="resultLocal"></label><br>
        <i>Data e Hora:</i> <label id="resultData"></label> <label id="resultHora"></label><br>
        <i>Carga Horária:</i> <label id="resultCarga"></label><br>
        <i>Conteúdos Abordados:</i> <label id="resultConteudos"></label><br>
        <i>Indicadores de Performance:</i> <label id="resultIndicadores"></label><br>
        <i>Materiais:</i> <label id="resultMateriais"></label><br>
        <i>Facilitadores: </i> <label id="resultFacilitadores"></label><br>
        <i>Lista de Presença: <label id="resultLista"></label></i>
    </div>
    <label id="voltaMenu2" class="SpaceEnviar" style="cursor: pointer; decoration: underline">VOLTAR AO MENU INICIAL</label>
</div>

The function searchBanco was defined as such:

function buscaBanco(numero){
    if (numero == '') {
        alert('Nenhum resultado encontrado!');
        $('#resultadoBusca').hide();
    }
    else {
        // Executa a consulta SQL. Se houver resultado, mostra na tela
        $('#resultadoBusca').show();
        <?php
            // class_exists('Servico') || include_once CLASS_PATH . 'Servico.class.php';
            $data['evento'] = Servico::getRetornosEventos();
            $event = $data['evento'];
        ?>
        document.getElementById('resultCodigo').textContent = <?php echo $event['id'] ?>
        document.getElementById('resultModelo').textContent = <?php echo $event['modelonome'] ?>
        document.getElementById('resultEvento').textContent = <?php echo $event['evento'] ?>
        document.getElementById('resultLocal').textContent = <?php echo $event['localevento'] ?>
        document.getElementById('resultData').textContent = <?php echo $event['dataevento'] ?>
        document.getElementById('resultHora').textContent = <?php echo $event['horaevento'] ?>
        document.getElementById('resultCarga').textContent = <?php echo $event['cargahoraria'] ?>
        document.getElementById('resultConteudos').textContent = <?php echo $event['conteudos'] ?>
        document.getElementById('resultIndicadores').textContent = <?php echo $event['indicadores'] ?>
        document.getElementById('resultMateriais').textContent = <?php if($event['chkapostila']=='1'){ echo "Apostila"; } else { echo "Nenhum"; } ?>
        document.getElementById('resultFacilitadores').textContent = <?php if($event['facilitadores']=='Externos'){ echo $event['externosnomes']; } else { echo $event['internosnomes']; } ?>
        document.getElementById('resultLista').textContent = <?php echo $event['listapresenca'] ?>
    }
}

And the function getRetornosEvents() on file servico.class.php (with Doctrine query) works like this:

public static function getRetornosEventos(){
    return self::$evento = self::setRetornosEventos();
}

public static function setRetornosEventos(){
    $sql = Doctrine_Query::create()
    ->select('e.id,u.nome AS usuarionome,
             (CASE WHEN modelo = 1 THEN "Sala de Aula"
                   WHEN modelo = 2 THEN "On The Job"
                   WHEN modelo = 3 THEN "Palestra"
                   WHEN modelo = 4 THEN "Workshop"
                   WHEN modelo = 5 THEN "Programas Institucionais"
                   WHEN modelo = 6 THEN "Outro" ELSE modelo END) as modelonome,
             (CASE WHEN programa = 1 THEN "Eu Faço Parte"
                   WHEN programa = 2 THEN "PDG"
                   WHEN programa = 3 THEN "PDL Unidades"
                   WHEN programa = 4 THEN "PDL Corporativo"
                   WHEN programa = 5 THEN "Jeito de Ser" ELSE programa END) as programa,
              outromodelo,evento,localevento,DATE_FORMAT(dataevento, "%d/%m/%Y") as dataevento,horaevento,
              cargahoraria,conteudos,indicadores,chkapostila,chkcopia,chkoutro,chknenhum,outromaterial,
             (CASE WHEN facilitadores = "E" THEN "Externos"
                   WHEN facilitadores = "I" THEN "Internos" ELSE facilitadores END) as facilitadores,
              externosnomes,externosempresas,internosnomes,internosempresas,listapresenca')
    ->from('WtEducEventos e')
    ->addFrom('WtUsuario u')
    ->where('e.usua_id = u.id')
    ->addWhere('e.id = ' . $_POST['buscaNumero']);
    $data = $sql->fetchArray();
    return $data;
}

However, the page is disfigured and there is no way to test the search. What could be wrong? Is there a semicolon missing from the search function? Is the Class_exists statement (usually in the Controller files) required in this case? Or suddenly some error in mixing PHP in java script or even with SQL query (Doctrine query).

I accept help and suggestions.

1 answer

0

Quotes are missing in the function buscaBanco. The way it is, you’ll be error syntax.

function buscaBanco(numero){
    if (numero == '') {
        alert('Nenhum resultado encontrado!');
        $('#resultadoBusca').hide();
    }
    else {
        // Executa a consulta SQL. Se houver resultado, mostra na tela
        $('#resultadoBusca').show();
        <?php
            // class_exists('Servico') || include_once CLASS_PATH . 'Servico.class.php';
            $data['evento'] = Servico::getRetornosEventos();
            $event = $data['evento'];
        ?>
        document.getElementById('resultCodigo').textContent = "<?php echo $event['id'] ?>"
        document.getElementById('resultModelo').textContent = "<?php echo $event['modelonome'] ?>"
        document.getElementById('resultEvento').textContent = "<?php echo $event['evento'] ?>"
        document.getElementById('resultLocal').textContent = "<?php echo $event['localevento'] ?>"
        document.getElementById('resultData').textContent = "<?php echo $event['dataevento'] ?>"
        document.getElementById('resultHora').textContent = "<?php echo $event['horaevento'] ?>"
        document.getElementById('resultCarga').textContent = "<?php echo $event['cargahoraria'] ?>"
        document.getElementById('resultConteudos').textContent = "<?php echo $event['conteudos'] ?>"
        document.getElementById('resultIndicadores').textContent = "<?php echo $event['indicadores'] ?>"
        document.getElementById('resultMateriais').textContent = "<?php if($event['chkapostila']=='1'){ echo "Apostila"; } else { echo "Nenhum"; } ?>"
        document.getElementById('resultFacilitadores').textContent = "<?php if($event['facilitadores']=='Externos'){ echo $event['externosnomes']; } else { echo $event['internosnomes']; } ?>"
        document.getElementById('resultLista').textContent = "<?php echo $event['listapresenca'] ?>"
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.