Jump to content

Pesquisa com filtros


Programar

Recommended Posts

Não estou conseguir fazer com que o while($linha=mysql_fetch_array($sql)) funcione.

Se fizer um echo (em baixo) ao sql ele mostra-me certo

SELECT * FROM tabela_caixa_total WHERE `data` between '2013-05-21' and '2013-06-28' AND `ID_CT` between '20' and '30'

mas depois n consigo mostrar os dados.

<?php
if( $_SERVER['REQUEST_METHOD']=='POST' )
{
 $where = Array();

 $data = getPost('data');
 $data1 = getPost('data1');
 $ret_inicial = getPost('ret_inicial');
 $ret_final = getPost('ret_final');

 if( $data ){ $where[] = " `data` between '{$data}' and '{$data1}'";}
 if( $ret_inicial ){ $where[] = " `ID_CT` between '{$ret_inicial}' and '{$ret_final}'"; }

 $sql = "SELECT * FROM tabela_caixa_total ";
 if( sizeof( $where ) )
 $sql .= ' WHERE '.implode( ' AND ',$where );

 echo $sql;//executar sql   <=====

 while($linha=mysql_fetch_array($sql)){
?>
<tr>
<td width="100"><?php echo $datatotal ?></td>
<td width="220"><?php echo $linha['valor'] ?></td>
<td><a href="?pg=39&ID_CT=<?php echo $ID_CT; ?>" title="Visualizar Relatório"><img src="../imagens/relatorio2.ico" width="25" height="25"></a></td>
<td><a href="#" onclick="window.open('relatorio_pesq_caixa.php?ID_CT=<?php echo $linha['ID_CT']; ?>&pat=1')" title="Imprimir Relatório"><img src="../imagens/impressora.ico" width="25" height="25"></a></td>
</tr>
<?php
 }
?>
</table>

<?php

}
//a cargo do leitor melhorar o filtro anti injection
function filter( $str ){
 return addslashes( $str );
}
function getPost( $key ){
 return isset( $_POST[ $key ] ) ? filter( $_POST[ $key ] ) : null;
}
?>
Link to comment
Share on other sites

Não estás a executar a query, por isso, sim.

Edited by brunoais

"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.