Programar Posted June 4, 2013 at 01:52 PM Report #510933 Posted June 4, 2013 at 01:52 PM 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; } ?>
Rui Carlos Posted June 4, 2013 at 02:58 PM Report #510971 Posted June 4, 2013 at 02:58 PM Vê isto: http://www.php.net/manual/en/mysqli.query.php Rui Carlos Gonçalves
Programar Posted June 4, 2013 at 05:13 PM Author Report #511004 Posted June 4, 2013 at 05:13 PM Já vi , mas o meu problema está em mostrar os dados da bd. se eu fizer um "echo" ao $sql ele manda me os valores correctos só não estou a conseguir ir buscar os valores a bd.
Rui Carlos Posted June 4, 2013 at 05:21 PM Report #511006 Posted June 4, 2013 at 05:21 PM Já percebeste como é que se executa uma query? É que sem perceberes isso é complicado conseguires ir buscar os valores à BD. Rui Carlos Gonçalves
Programar Posted June 4, 2013 at 05:24 PM Author Report #511007 Posted June 4, 2013 at 05:24 PM (edited) sim, e eu não estou a executar direito??? Edited June 4, 2013 at 05:26 PM by Programar
brunoais Posted June 4, 2013 at 05:33 PM Report #511012 Posted June 4, 2013 at 05:33 PM (edited) Não estás a executar a query, por isso, sim. Edited June 4, 2013 at 05:33 PM 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%.
I-NOZex Posted June 4, 2013 at 05:33 PM Report #511014 Posted June 4, 2013 at 05:33 PM tens a ligaçao feita correctamente? nao da erros? testa com echos ou print_r... B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
Programar Posted June 4, 2013 at 05:35 PM Author Report #511015 Posted June 4, 2013 at 05:35 PM (edited) Esta a ligação está correta... E n n dá erros. Edited June 4, 2013 at 05:35 PM by Programar
Rui Carlos Posted June 4, 2013 at 05:36 PM Report #511017 Posted June 4, 2013 at 05:36 PM sim, e eu não estou a executar direito??? O echo $sql;//executar sql não executa a query, apenas envia o texto da query para o output. Vê a função que te indiquei anteriormente. E podes também ver este link: http://www.php.net/manual/en/mysqli.quickstart.statements.php Rui Carlos Gonçalves
Programar Posted June 4, 2013 at 05:43 PM Author Report #511021 Posted June 4, 2013 at 05:43 PM (edited) Sim, mas o while que está abaixo deveria estar. Eu sei mas por isso mesmo o echo $sql;//executar está a mostrar os valores correctos. Não estou a conseguir persevere onde esta o meu erro.... Edited June 4, 2013 at 05:47 PM by Programar
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now