Fórum PROBLEMA COM FUNÇÃO JAVASCRIPT / PHP #582172
06/06/2017
0
Bom dia,
Preciso desenvolver um código para que caso um combo box seja seleciona alguma opção ele efetue determinado SELECT (utilizando alguns WHERE), e caso não seja selecionado ele execute o select completo (sem cláusula WHERE).
Construí o seguinte código:
Onde a função define select, irá de fato definir qual será o select executado. Estas chamadas de funções estariam em uma segunda classe chamada: exportExcel1.php
Preciso desenvolver um código para que caso um combo box seja seleciona alguma opção ele efetue determinado SELECT (utilizando alguns WHERE), e caso não seja selecionado ele execute o select completo (sem cláusula WHERE).
Construí o seguinte código:
function defineSelect(){
var areaEsco = $("#areaEscolhida").val();
var cargoEsco = $("#cargoEscolhido").val();
if(areaEsco == null){
if (cargoEsco == null){
alert("TESTE");
selecionaTudo();
}else{
selecionaCargo();
}
}selecionaArea();
}
</script>
</head>
<body>
<div class="col-md-12">
<img src="imagens/layout/logo.png" class="logoCentral">
</div>
<div class="col-md-6 col-md-offset-3 espacamentoTituloResultado text-center">
<h2>RESULTADO</h2>
<h3>Levantamento Funcional</h3>
</div>
<!--Função PHP para selecionar áreas-->
<?php
include('../includes/conecxao.php');
$result = $mysqli->query("SELECT seguimentosOperacionaisTituloAtualFuncionario "
. "FROM tbl_funcionarios "
. "GROUP BY seguimentosOperacionaisTituloAtualFuncionario ASC");
?>
<!--Função PHP para selecionar cargos-->
<?php
include('../includes/conecxao.php');
$result2 = $mysqli->query("SELECT idCargo,nomeCargo FROM tbl_cargos");
?>
<!--Campo COMBO BOX-->
<form method="post" action="">
<div class="form-group col-md-4 col-md-offset-4 espacamentoCampoArea">
<label for="areaEscolhida">Selecione a área (Opcional):</label>
<select id="areaEscolhida" class="form-control">
<option value="selecione">Selecione...</option>
<?php while ($area = $result->fetch_object()) { ?>
<option value="<?php echo $area->seguimentosOperacionaisTituloAtualFuncionario ?>">
<?php echo $area->seguimentosOperacionaisTituloAtualFuncionario ?></option>
<?php } ?>
</select>
</div>
<!--Campo COMBO BOX-->
<div class="form-group col-md-4 espacamentoCargo">
<label for="cargoEscolhido">Selecione o cargo (Opcional):</label>
<select id="cargoEscolhido" class="form-control">
<option value="selecione">Selecione...</option>
<?php while ($cargo = $result2->fetch_object()) { ?>
<option value="<?php echo $cargo->idCargo ?>">
<?php echo $cargo->nomeCargo ?></option>
<?php } ?>
</select>
</div>
<button type="button" class="btn btn-success " onclick="selecaoAreaCargo()">Pesquisar</button>
</form>
<div class="col-md-8 col-md-offset-2 tabelaRespondidos">
<ul class="nav nav-tabs nav-justified">
<li role="presentation" class="active"><a href="#respondidos" data-toggle="tab">Formulários Respondidos</a></li>
<li role="presentation"><a href="#naoRespondidos" data-toggle="tab">Formulários não Respondidos</a></li>
</ul>
<br>
<div class="tab-content">
<div class="tab-pane active" id="respondidos">
<table class="table tabela1">
<thead>
<tr>
<th>Nome do funcionário</th>
<th>Supervisor</th>
<th>Ação</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script id="tmplLinha" type="text/template">
<tr>
Onde a função define select, irá de fato definir qual será o select executado. Estas chamadas de funções estariam em uma segunda classe chamada: exportExcel1.php
function selecionaTudo(){
// Nome do Arquivo do Excel que será gerado
$arquivo = 'exportacao_levantamento_funcional.xls';
// Criamos uma tabela HTML com o formato da planilha para excel
$tabela = '<table border="1">';
$tabela .= '<tr>';
$tabela .= '<td colspan="46"><b>Formulario - Levantamento Funcional - Respostas</b></td>';
$tabela .= '</tr>';
$tabela .= '<tr style="text-align: center;">';
$tabela .= '<td rowspan="2"><b>01.01.00-NOM</b></td>';
$tabela .= '<td rowspan="2"><b>01.02.00-MTR</b></td>';
$tabela .= '<td rowspan="2"><b>01.03.00-CRG</b></td>';
$tabela .= '<td rowspan="2"><b>01.03.00-ADM</b></td>';
$tabela .= '<td rowspan="2"><b>01.04.00-LTC</b></td>';
$tabela .= '<td rowspan="2"><b>02.01.00-SMD</b></td>';
$tabela .= '<td rowspan="2"><b>02.02.00-SIM</b></td>';
....
$resultado = $mysqli->query("SELECT * from tbl_funcionarios tblFunc INNER JOIN tbl_levantamento_funcional tblLevFunc ON tblFunc.fkIdLevFunc = tblLevFunc.idLevFunc INNER JOIN tbl_atividade_funcionario_lev_func tblAtvLevFunc ON tblFunc.fkIdLevFunc = tblAtvLevFunc.fkIdLevFunc INNER JOIN tbl_contatos_cargo_lev_func tblContCargLevFunc ON tblFunc.fkIdLevFunc = tblContCargLevFunc.fkIdLevFunc INNER JOIN tbl_subordinados_lev_func tblSubLevFunc ON tblFunc.fkIdLevFunc = tblSubLevFunc.fkIdLevFunc") or die (mysql_error());
while($dados = mysqli_fetch_array($resultado)){
$tabela .= '<tr style="text-align: center;">';
$tabela .= '<td>'.utf8_encode($dados['nomeFuncionario']).'</td>';
$tabela .= '<td>'.utf8_decode($dados['numeroMatriculaFuncionario']).'</td>';
$tabela .= '<td>'.utf8_decode($dados['tituloCargo']).'</td>';
$tabela .= '<td>'.utf8_decode($dados['dataAdminissaoFuncionario']).'</td>';
$tabela .= '<td>'.utf8_decode($dados['lotacao']).'</td>';
$tabela .= '<td>'.utf8_decode($dados['tituloCargoSuperiorMediato']).'</td>';
$tabela .= '<td>'.utf8_decode($dados['tituloCargoSuperiorImediato']).'</td>';
$tabela .= '<td>'.utf8_decode($dados['recebeDemanda']).'</td>';
$tabela .= '<td>'.utf8_decode($dados['submeteDemanda']).'</td>';
...
$tabela .= '</table>';
// Força o Download do Arquivo Gerado
header ('Cache-Control: no-cache, must-revalidate');
header ('Pragma: no-cache');
header('Content-Type: application/x-msexcel');
header ("Content-Disposition: attachment; filename=\\"{$arquivo}\\"");
echo $tabela;
} //fecha funcao selecionaTudo()
?>
Salute Especializadas
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)