Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Gomes0707

[Resolvido] Consulta SQL

Recommended Posts

Olá,pessoal como faço para filtrar nessa consulta para mostrar a mesma opção de filtragem que está na imagem circulada

imgifd.jpg

Eu consigo filtrar por Despesa ou Receita mais gostaria que quando selecionar a igreja ter opção de filtrar por ambos os dois despesa e receita juntos como está na imgem

desde já agradeço

SELECT DISTINCT fina_tipo FROM financeiro  INNER JOIN igreja ON fina_ig_id = ig_id WHERE ig_nome = '$tipo'

Compartilhar este post


Link para o post
Compartilhar em outros sites

Depende de como foi montada as "Combo" Igreja e Tipo de Lançamento.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Depende de como foi montada as "Combo" Igreja e Tipo de Lançamento.

O código do Combo

<?php require_once('Connections/config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
 if (PHP_VERSION < 6) {
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 }

 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 switch ($theType) {
   case "text":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;    
   case "long":
   case "int":
     $theValue = ($theValue != "") ? intval($theValue) : "NULL";
     break;
   case "double":
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
     break;
   case "date":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;
   case "defined":
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
     break;
 }
 return $theValue;
}
}

mysql_select_db($database_config, $config);
$query_RsLista_ig = "SELECT * FROM igreja";
$RsLista_ig = mysql_query($query_RsLista_ig, $config) or die(mysql_error());
$row_RsLista_ig = mysql_fetch_assoc($RsLista_ig);
$totalRows_RsLista_ig = mysql_num_rows($RsLista_ig);
?>
<?php require_once('Connections/conexao.php'); ?>
<?php
if($_GET['igre']>='1'){
$igre = $_GET['igre'];
}else{
$igre =$_POST['igre'];
}
if($_GET['tipo']>='1'){
$tipo = $_GET['tipo'];
}else{
$tipo =$_POST['tipo'];
}
if($_GET['ano']>='1'){
$ano = $_GET['ano'];
}else{
$ano =$_POST['ano'];
}
if($_GET['ms']>='1'){
$ms = $_GET['ms'];
}else{
$ms =$_POST['ms'];
}
$pag = "$_GET[pag]";
if($pag >= '1'){
$pag = $pag;
}else{
  $pag = '1';
}
$maximo = '2';
$inicio = ($pag * $maximo) - $maximo;
$listar_finaceiro = mysql_query ("SELECT *,date_format(fina_data,'%d/%m/%Y')AS DATA FROM financeiro   INNER JOIN igreja ON ig_id = fina_ig_id
WHERE ig_nome = '$igre' AND fina_tipo ='$tipo' AND MONTHNAME(fina_data)  = '$ms' AND YEAR(fina_data) = '$ano'
LIMIT $inicio,$maximo ")
or die (mysql_error());
$row_fin = mysql_num_rows($listar_finaceiro);


$listar_sum = mysql_query ("SELECT *,SUM(fina_valor)as TotalValor,date_format(fina_data,'%d/%m/%Y')AS DATA FROM financeiro INNER JOIN igreja ON ig_id = fina_ig_id
WHERE ig_nome = '$igre' AND fina_tipo ='$tipo' AND MONTHNAME(fina_data)  = '$ms' AND YEAR(fina_data) = '$ano'
")
or die (mysql_error());
$row_sum = mysql_num_rows($listar_sum);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sistema de Gerenciamento de Igrejas</title>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/filtro.js"></script>
<link href="../admin/css/estilo_admin.css" rel="stylesheet" type="text/css" />
<link href="../SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<script src="../SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
</head>
<body>


<table width="780" border="0" align="center" style="background:#3B515C; border-collapse:collapse">
 <tr>
   <td align="center"><form id="filtrar" name="filtrar" method="post" action="listar1.php">
     <table width="770" border="0" align="center">
       <tr>
         <td width="160"><span id="spryselect1">
           <select name="igre" id="igre">
             <option value="-1">Selecione uma opção</option>
             <?php
do {  
?>
             <option value="<?php echo $row_RsLista_ig['ig_nome']?>"><?php echo $row_RsLista_ig['ig_nome']?></option>
             <?php
} while ($row_RsLista_ig = mysql_fetch_assoc($RsLista_ig));
 $rows = mysql_num_rows($RsLista_ig);
 if($rows > 0) {
     mysql_data_seek($RsLista_ig, 0);
  $row_RsLista_ig = mysql_fetch_assoc($RsLista_ig);
 }
?>
           </select>
           </td>
         <td width="159"><span id="spryselect2">
           <select name="tipo" id="tipo">
             <option value="-1">Selecione uma opção</option>
</select>
          </td>
         <td width="143"><span id="spryselect3">
           <select name="ano" id="ano">
             <option value="-1">Selecione um ano</option>
</select>
          </td>
         <td width="140"><span id="spryselect4">
           <select name="ms" id="ms">
             <option value="-1">Selecione um mês</option>
</select>
           </td>
         <td><input type="submit" name="filtrar" id="filtrar" value="Filtrar" /></td>
         </tr>
     </table>
   </form></td>
   </tr>
</table>

<table width="780" border="1" align="center" cellpadding="2" style=" border-collapse:collapse">
 <tr style=" background:#3B515C;color:#FFF; font:12 Arial, Helvetica, sans-serif; font-weight:bold">
   <td width="143" align="center">Igreja</td>
   <td width="149" align="center">Tipo</td>
   <td width="152" align="center">Nome</td>
   <td colspan="2" align="center">Data</td>
   <td width="157" colspan="2" align="center">Valor</td>
 </tr>
   <?php $vTotal = 0;?>
   <?php 
 while($rows = mysql_fetch_array($listar_finaceiro)){
 $fina_tipo =$rows['fina_tipo'];
 $ig_nome =$rows['ig_nome'];
 $fin_nome =$rows['fina_nome'];
 $fin_data =$rows['DATA'];
 $fin_valor =$rows['fina_valor'];
 if($row_fin > 0){
 ?>
   <?php $vTotal = $vTotal + $fin_valor;?>

   <tr>

     <td align="center"><?php echo $ig_nome; ?></td>
     <td align="center"><?php echo $fina_tipo  ?></td>
     <td align="center"><?php echo $fin_nome ?></td>
     <td width="134" align="center"><?php echo $fin_data ?></td>
     <td colspan="3" align="center">R$ <?php echo number_format ($fin_valor,2,',','.'); ?></td>
   </tr>
   <?php }}?>
<?php if($row_fin > 0){?>
    <tr style=" background:#7ca6b2;color:#FFF; font:12 Arial, Helvetica, sans-serif; font-weight:bold">
   <td width="143" align="center">Igreja</td>
   <td width="149" align="center">Tipo</td>
   <td width="152" align="center">Ano</td>
   <td colspan="2" align="center">Mês</td>
   <td width="157" colspan="2" align="center">Soma da página</td>
   </tr>

     <tr>
       <td align="center"><?php echo $igre;?></td>
       <td align="center"><?php echo $tipo;?></td>
       <td align="center"><?php echo $ano;?></td>
       <td width="134" align="center"><?php echo $ms;?></td>
       <td colspan="3" align="center">R$ <?php echo number_format ($vTotal,2,',','.'); ?></td>
     </tr>

   <?php }?>
   <?php
    while($rowsf = mysql_fetch_array($listar_sum)){

     $fin_total =$rowsf['TotalValor'];
   if($row_fin > 0){
  ?>
 <tr style=" background:#3B515C;color:#FFF; font:12 Arial, Helvetica, sans-serif; font-weight:bold">
       <td align="center"></td>
       <td align="center"></td>
       <td align="center"></td>
       <td width="134" align="center"></td>
       <td colspan="3" align="center">Total Geral</td>
     </tr>
     <tr>
       <td align="center"></td>
       <td align="center"></td>
       <td align="center"></td>
       <td width="134" align="center"></td>
       <td colspan="3" align="center">R$ <?php echo number_format ($fin_total,2,',','.'); ?></td>
     </tr>
     <?php }}?>
</table>






<?php if($row_fin  > 0){ ?>
<table width="780" border="0" align="center" id="paginator">
 <tr>
<td align="center"><?php $listar_sql = mysql_query ("SELECT *,date_format(fina_data,'%d/%m/%Y')AS DATA
FROM financeiro  INNER JOIN igreja ON ig_id = fina_ig_id
WHERE ig_nome = '$igre' AND fina_tipo ='$tipo' AND MONTHNAME(fina_data)  = '$ms' AND YEAR(fina_data) = '$ano'")
or die (mysql_error());
$total = mysql_num_rows($listar_sql);
$paginas = ceil($total/$maximo);
$links = 5;
echo "<a href=\"?tipo=$tipo&igre=$igre&ano=$ano&ms=$ms&pag=1\">Primeira página</a>   ";
for ($i = $pag-$links; $i <= $pag-1; $i++){
if($i <= 0){
}else{
echo"<a href=\"?tipo=$tipo&igre=$igre&ano=$ano&ms=$ms&pag=$i\"> $i</a>   ";
}
}echo "$pag    ";

for ($i = $pag +1;  $i <= $pag+$links; $i++){
if($i > $paginas){

}else{
echo"<a href=\"?tipo=$tipo&igre=$igre&ano=$ano&ms=$ms&pag=$i\"> $i</a>   ";
}
}
echo "<a href=\"?tipo=$tipo&igre=$igre&ano=$ano&ms=$ms&pag=$paginas\">Última página</a>   ";
?>
</td>
 </tr>
</table>
<?php }?>
<?php if($row_fin == 0){ ?>
 <table width="780" border="0" align="center">
   <tr>
     <td align="center" style="color:#3b515c; font:14 Arial, Helvetica, sans-serif">Não há dados para exibir, selecione as opções para realizar a filtragem!</td>
     </tr>
 </table>
<?php   }?>

</body>
</html>
<?php
mysql_free_result($RsLista_ig);
?>

O código do Filtro em Jquery

$(function(){
$("select[name=igre]").change(function(){
beforeSend:$("select[name=tipo]").html('<option value="0">aguarde carregando...</option>')
var tipo = $("select[name=igre]").val();
$.post("tipo.php",{tipo:tipo},function(pega_igre){
complete:$("select[name=tipo]").html(pega_igre)



$("select[name=tipo]").change(function(){
beforeSend:$("select[name=ano]").html('<option value="0">aguarde carregando...</option>')
var ano = $("select[name=tipo]").val();
$.post("ano.php",{ano:ano},function(pega_ano){
complete:$("select[name=ano]").html(pega_ano)




$("select[name=ano]").change(function(){
beforeSend:$("select[name=ms]").html('<option value="0">aguarde carregando...</option>')
var ms = $("select[name=ano]").val();
$.post("mes.php",{ms:ms},function(pega_ms){
complete:$("select[name=ms]").html(pega_ms)

           })
        })
     })
 })


})
})
})

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pelo que entendo "Todas as Igrejas" veio da tabela

então o sql ficaria algo assim

 

SELECT DISTINCT fina_tipo 
FROM financeiro  
 INNER JOIN igreja ON fina_ig_id = ig_id 
WHERE (ig_nome = '$tipo' or '$tipo' = 'Todas as Igrejas')

 

Não conheço PHP, me perdoe se escrevi batatada.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Pelo que entendo "Todas as Igrejas" veio da tabela

então o sql ficaria algo assim

 

SELECT DISTINCT fina_tipo 
FROM financeiro  
 INNER JOIN igreja ON fina_ig_id = ig_id 
WHERE (ig_nome = '$tipo' or '$tipo' = 'Todas as Igrejas')

 

Não conheço PHP, me perdoe se escrevi batatada.

Valeu Motta muito obrigado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.