joaocasta Posted October 6, 2012 at 08:01 PM Report #478061 Posted October 6, 2012 at 08:01 PM Boas, como poderei fazer com que os dados que tenho na página se actualizem ao pressionar o botão do formulário? <?php include "config.php"; session_start(); ?> <form method="POST" name="formcombustiveis" id="formcombustiveis" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="checkbox" name="C13" value="ON"><font size="1">Comprado Quantidade <textarea rows="1" name="litros" cols="7">Litros</textarea> <select size="1" name="Limpeza39"> <option>Galp</option> <option>De outro País</option> <option>Repsol</option> <option>Marca branca</option> <option>Outra marca</option> <option>Bp</option> </select> <input type="submit" value="Submit" name="submitform"> </form> <p align="center"><font color="#FF0000">Resultado em Litros</font></p> <table border="0" width="100%"> <?php $id_utilizador = (int)$_SESSION['id']; $query1 = mysql_query("SELECT combustiveis.id, SUM(combustiveis.combustiveis) AS Quantidade, combustiveis.id_utilizador, combustiveis_select.combustiveis_marca FROM combustiveis INNER JOIN combustiveis_select ON combustiveis.id_referente_combustiveis = combustiveis_select.id WHERE combustiveis.id_utilizador='$id_utilizador' GROUP BY combustiveis_select.combustiveis_marca"); while ($row = mysql_fetch_array($query1)) { echo '<tr> <td width="73"><font size="1">'; echo "<a href='editar_consumido_mim.php?tipo=combustiveis&marca=" . $row['combustiveis_marca'] . "&id=" . $row['id'] . "'>" . $row['combustiveis_marca'] . ""; echo '</font></td>'; echo '<td><font size="1" color="#0000FF">'; echo $row['Quantidade'] . 'L'; echo '</font></td> </tr>'; } ?> </table> <p align="center"> </p> <p align="center"><font size="1">Total</font></p> <?php $query2 = mysql_query("SELECT SUM(combustiveis) AS combustiveis FROM combustiveis WHERE id_utilizador='$id_utilizador'"); while ($row = mysql_fetch_array($query2)) { echo '<p align="center"><font size="1" color="#0000FF">'; echo $row['combustiveis'] . ' Litros'; echo '</font></p> <p align="center"> </p>'; } ?> agora queria adicionar o resto pra actualizar sem refresh.
joaocasta Posted October 7, 2012 at 08:44 AM Author Report #478105 Posted October 7, 2012 at 08:44 AM (edited) Já tenho este código: ajax-example.php <html> <head> <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> function addRecord() { var term_name = $('#combustiveis').val(); //Storing the value of textbox into a variable if(term_name == '') //Checking for NULL { $('#propspectDiv').html('Escreva numeros'); //Prints the progress text into our Progress DIV $('#combustiveis').addClass('error'); //Adding the error class to the progress DIV return; } else{ $('#combustiveis').removeClass('error'); $('#propspectDiv').removeClass('error'); //Removing the error class from the progress DIV $.ajax({ url : '1data.php', //Declaration of file, in which we will send the data data:{ "combustiveis" : term_name //we are passing the name value in URL }, success : function(data){ window.setTimeout(function(){ $('#propspectDiv').html('Quantidade adicionada'); //Prints the progress text into our Progress DIV $('#data').css("display","block"); //Changes the style of table from display:none to display:block $('#data').html(data); //Prints the data into the table }, 2000); } }); } } </script> </head> <body> <div id="wrapper"> <input type="text" id="combustiveis" value="Quantidade" /> <input type="button" value="Submit" onclick="addRecord()" /> <div id="propspectDiv"></div> <table id="data" border="1" cellspacing="0" cellpadding="0" width="75" style="display:none;"></table> </div> </body> </html> 1data.php <?php $combustiveis = $_REQUEST['combustiveis']; include "config.php"; session_start(); $sql = mysql_query("INSERT INTO combustiveis (`combustiveis`) VALUES ('".$combustiveis."')"); $query2 = mysql_query("SELECT SUM(combustiveis) AS combustiveis FROM combustiveis"); while ($row = mysql_fetch_array($query2)) { echo '<p align="center"><font size="1" color="#0000FF">'; echo $row['combustiveis'] . ' Litros'; echo '</font></p> <p align="center"> </p>'; } ?> queria que me mostrasse na pagina ajax-example.php os mesmos dados que mostra a pagina 1data.php sem refresh.. Nao sei se me conseguem entender. :| Edited October 7, 2012 at 08:49 AM by joaocasta
brunoais Posted October 7, 2012 at 05:05 PM Report #478150 Posted October 7, 2012 at 05:05 PM Sem a ajuda da indentação e com código com erros (não acredito que estejas a suar HTML3), não vou lá. "[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%.
joaocasta Posted October 7, 2012 at 06:18 PM Author Report #478153 Posted October 7, 2012 at 06:18 PM é o unico codigo q tenho.
jfosorio Posted October 12, 2012 at 10:53 PM Report #478941 Posted October 12, 2012 at 10:53 PM Experimenta alterar a tabela com o id="data" para uma div. CSS 3D Text - Partilha mensagens em 3D com os teus amigos no Facebook! Portal de Informática it4life - Emprego, notícias, fórum, comunidade.
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