Ver Mensaje Individual
  #5 (permalink)  
Antiguo 28/04/2010, 09:29
maxwellxp
 
Fecha de Ingreso: abril-2010
Mensajes: 143
Antigüedad: 14 años
Puntos: 0
Respuesta: problema code PHP

resultado:
Código HTML:
array(10) { [0]=>  string(1) "1" ["id"]=>  string(1) "1" [1]=>  string(1) "4" ["num1"]=>  string(1) "4" [2]=>  string(1) "3" ["num2"]=>  string(1) "3" [3]=>  string(1) "7" ["resultado"]=>  string(1) "7" [4]=>  string(1) "2" ["sumatoria"]=>  string(1) "2" } array(10) { [0]=>  string(2) "36" ["id"]=>  string(2) "36" [1]=>  string(1) "6" ["num1"]=>  string(1) "6" [2]=>  string(1) "5" ["num2"]=>  string(1) "5" [3]=>  string(2) "11" ["resultado"]=>  string(2) "11" [4]=>  string(1) "0" ["sumatoria"]=>  string(1) "0" }
codigo con vardump
Código HTML:
<?php
if(isset($_POST['noticia'])) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$numres = $num1 + $num2;
mysql_connect("localhost","root") or die ("no se pudo conectar");
mysql_select_db("prueba");
mysql_query("UPDATE numero SET sumatoria = sumatoria + 1") or die(mysql_error());
mysql_query("INSERT INTO numero (num1, num2, resultado) VALUES ('$num1', '$num2', '$numres')") or die(mysql_error());
$query2 = mysql_query("SELECT * FROM numero") or die(mysql_error());
while ($row = mysql_fetch_array($query2)) {
$sumador = $row['sumatoria'];
var_dump($row);
}
$query = mysql_query("SELECT * FROM numero WHERE id=$sumador") or die(mysql_error());
while ($res = mysql_fetch_array($query)) {
$num1_b = $res['num1'];
$num2_b = $res['num2'];
$numres_b = $res['resultado'];
var_dump($res);
}
}
?>
<!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>Documento sin t&iacute;tulo</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
    <input type="text" name="num1" id="num1" />
    </label> 
    + 
    <label>
    <input type="text" name="num2" id="num2" />
    </label>
    <input type="submit" name="noticia" id="noticia" value="Enviar" /></p>
  <p>Resultado actual:
    <?php if(isset($_POST['noticia'])) { echo $numres; } ?>
  </p>
<p>Operadores Anteriores: <?php if(isset($_POST['noticia'])) { echo $res['num1']; } ?> + <?php if(isset($_POST['noticia'])) { echo $res['num2']; } ?></p>
    <p> Resultado anterior: <?php if(isset($_POST['noticia'])) { echo $res['resultado']; }?></p>

  <label></label>
</form>
</body>
</html>