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.
Código (PHP):
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.
Código (PHP):
<?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;
}
?>
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;
}
?>