
FORMULARIOS
Publicado por Robbmejia (26 intervenciones) el 19/09/2013 00:49:36
Hola como están, espero que bien tengo 2 problemas con "FOR" Y "IF" creo se llaman bucles, no los se usar muy bien. Quiero que aya un conteo desde #numero1 y que vayan ascendiendo (un en uno) hasta que llegue al final y imprima la suma de todos los dígitos del primero al ultimo. La idea es se pueda ingresar datos mediante el formulario, estos pueden ser "GET" o "POST"
algo así eJEMPLO:
#INICIAL = 3
#FINAL = 6
3+
4+
5+
6+
suma = 18
Hasta el momento tengo mis códigos así que tendría que cambiar o modificar.
-------------------------------------------------TENGO ESTO HASTA EL MOMENTO---------------------------------------------------
--------------------------------------------------------------------------------------------------------
Este también:
En este caso son valores que se ingresarían:INICIAL, FINAL Y INCREMENTO. Quiero que también imprima desde el inicial y ir ascendiendo según sea el incremento que se pueda dar, hasta llegar al numero final que se ingresara también mediante la casilla del formulario. algo así:
(EJEMPLO)
#INICIAL = 2
#FINAL = 11
#INCREMENTO = 3
2
5
8
11
------------------------------------------------------TENGO ESTO HASTA EL MOMENTO------------------------------------------------
-------------------------------------------------------------------------------------------------------
GRACIAS. SALUDOS.
algo así eJEMPLO:
#INICIAL = 3
#FINAL = 6
3+
4+
5+
6+
suma = 18
Hasta el momento tengo mis códigos así que tendría que cambiar o modificar.
-------------------------------------------------TENGO ESTO HASTA EL MOMENTO---------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<form action="" method="post">
<label>INICIAL:</label><input type="text" name="inicial"><br>
<label>FINAL:</label><input type="text" name="final"><br>
<input type="submit" value="Enviar" name="enviar">
</form>
<br>
<?php
error_reporting(0);
$inicial = (isset($_POST['inicial'])?$_POST['inicial']:"0");
$final = (isset($_POST['final'])?$_POST['final']:"0");
$suma = $final($final+1)/2;
if($inicial>0 && $final>=$inicial)
{
for($i=$inicial;$i<=$final;$i++)
{
if($i+$i)
{
echo "<br>".$i."+";
}else{
echo "<br>".$i."+";
}
}
echo $suma;
}
?>
--------------------------------------------------------------------------------------------------------
Este también:
En este caso son valores que se ingresarían:INICIAL, FINAL Y INCREMENTO. Quiero que también imprima desde el inicial y ir ascendiendo según sea el incremento que se pueda dar, hasta llegar al numero final que se ingresara también mediante la casilla del formulario. algo así:
(EJEMPLO)
#INICIAL = 2
#FINAL = 11
#INCREMENTO = 3
2
5
8
11
------------------------------------------------------TENGO ESTO HASTA EL MOMENTO------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<form action="" method="post">
<label>INICIAL:</label><input type="text" name="inicial"><br>
<label>FINAL:</label><input type="text" name="final"><br>
<label>INCREMENTO:</label><input type="text" name="incremento"><br>
<input type="submit" value="Enviar" name="enviar">
</form>
<br>
<?php
error_reporting(0);
$inicial = (isset($_POST['inicial'])?$_POST['inicial']:"0");
$final = (isset($_POST['final'])?$_POST['final']:"0");
$incremento = (isset($_POST['incremento'])?$_POST['incremento']:"0");
if($inicial>0 && $final >= $i)
{
for($i=$inicial;$i<=$final;$i+=$incremento)
{
if($incremento > $inicial)
{
echo "<br>".$inicial;
}else{
echo "<br>".$final;
}
}
};
?>
-------------------------------------------------------------------------------------------------------
GRACIAS. SALUDOS.
Valora esta pregunta


0