rodrigolfm Posted July 20, 2014 Report Share Posted July 20, 2014 (edited) Boa Tarde , Gostaria da ajuda de vocês , como que eu passo esse codigo para php . Sou novo no php , qaulquer ajuda sera bem vinda . até ja comecei o codigo em php Obrigado CODIGO PASCALZIM Program SimuladordeCargas ; Var n1,n2:Integer ; Begin Writeln(' '); Writeln('Digite a Distancia '); Readln(n1); Writeln('Digite o volume do Material em m3'); Readln(n2); if (n1 >=45) then Writeln('O total a pagar ', 1.40 * n1 + 12 * n2 ,(' '),('Euros') ) else Writeln ('Distancia Curta , Minimo 45 km' ) ; ReadLn; End. Edited June 29, 2015 by rodrigolfm Link to comment Share on other sites More sharing options...
rodrigolfm Posted July 20, 2014 Author Report Share Posted July 20, 2014 (edited) ja fiz algumas coisa , e esta funcionando , porem quando clico em Simular ele me manda um valor errado . eu queria por essa formula 1.40 * txt_km + 12 * txt_m3 = Resultado FINAL EM EUROS € <html xmlns="<a href="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Simulador Online</title> </head> <body> <?php if (isset($_POST['txt_km'])) { echo "<h1><font color='red'>Resultado = € " . 1.40 * ($_POST['txt_km'] + 12.00 * $_POST['txt_m3']) . "</font></h1><p/>"; } ?> <h1>Simulador</h1> <form id="id_simulador" name="Simulador" method="post" action="<?php echo "http://" . $_SERVER['HTTP_HOST'] . "/rodrigo/index.php"; ?>"> K.M : <input name="txt_km" type="text" size="20" maxlength="5" /> METROS CUBICOS (M3): <input name="txt_m3" type="text" size="20" maxlength="5" /> <p/> <input name="Simular" type="submit" value="Simular" /> </form> </body> </html> Edited July 20, 2014 by rodrigolfm Link to comment Share on other sites More sharing options...
N3lson Posted July 20, 2014 Report Share Posted July 20, 2014 (edited) Cria uma função e em seguida chama-a function simular($x,$x2){ $v = 1.40 * ($x + 12.00 * $x2) ; return $v; } if (isset($_POST['txt_km'])) { echo "<h1><font color='red'>Resultado = " .simula($_POST['txt_km'] ,$_POST['txt_m3']) . "</font></h1><p/>"; } Supondo que pretendes enviar para o mesmo ficheiro, substitui o sublinhado Onde está o action="<?php echo http://" . $_SERVER['HTTP_HOST'] . "/rodrigo/index.php"; ?> Coloca $_SERVER['PHP_SELF'] Edited July 20, 2014 by N3lson 1 Report You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it. Link to comment Share on other sites More sharing options...
rodrigolfm Posted July 20, 2014 Author Report Share Posted July 20, 2014 (edited) Boas funciona Edited June 29, 2015 by rodrigolfm Link to comment Share on other sites More sharing options...
rodrigolfm Posted July 21, 2014 Author Report Share Posted July 21, 2014 (edited) nao sei se essa foi a melhor maneira Edited June 29, 2015 by rodrigolfm geshi Link to comment Share on other sites More sharing options...
rodrigolfm Posted July 21, 2014 Author Report Share Posted July 21, 2014 (edited) ja consegui resolver essa questao da variavel >45. if ( isset($_POST['txt_km' ]) && $_POST['txt_km'] >= 45 ) { echo "<h1><font color='red'>Resultado = € " .simular($_POST['txt_km'] ,$_POST['txt_m3']) . "</font></h1><p/>"; } else echo "<h1><font color='red'> Distancia Curta , Minimo 45 km </font></h1><p/>"; Edited June 29, 2015 by rodrigolfm Link to comment Share on other sites More sharing options...
rodrigolfm Posted July 21, 2014 Author Report Share Posted July 21, 2014 (edited) Boas pessoal , tenho outra questao que queria ajuda de como fazer , se no caso for digitado pelo usuario algum numero na variavel $_POST['txt_m3'] ,se o numero for de 1..5 ele alterava o valor de 12 que no caso ia multiplicar pela variavel (12 * $x2)) ; , 1..5 = 1 5..10 = 1.14 10..15 = 1.30 15..20= 1.45 essas quatro situação . como eu poderia fazer isso em php nesse codigo . Obrigado segue o codigo . <html xmlns="<a href="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Simulador Online</title> <style type="text/css"> <!-- .style2 { color: #999999; font-weight: bold; } #LayerBotao { position:absolute; width:61px; height:32px; z-index:1; left: 167px; top: 180px; } --> </style> </head> <body> <style type="text/css"> .botao{ font-size:20px; font-family:Verdana,Helvetica; font-weight:bold; color:white; background:#638cb5; border:0px; width:100px; height:40px; } </style> <p> <?php // FUNÇÃO SIMULAR ! // FORMULA COMPLETA COM IVA ! function simular($x ,$x2 ){ $v = ((1.40 * $x) + (12 * $x2)) * 23 / 100 + ((1.40 * $x) + (12 * $x2)) ; // + 23% DE IVA ! return $v; } if ( isset($_POST['txt_km' ]) && $_POST['txt_km'] <= 44 ) { echo "<h1><font color='red'> Distancia Curta , Minimo 45 km </font></h1><p/>"; } else echo "<h1><font color='red'>Valor Total = € " .simular($_POST['txt_km'] ,$_POST['txt_m3']) . "</font></h1><p/>"; ?> </p> <h1>Simulador de Carga</h1> <form id="id_simulador" name="Simulador" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> <p><strong>k.m :</strong> <input name="txt_km" type="text" size="20" maxlength="5" /> <strong> Metro Cubico ( m³ ): </strong> <input name="txt_m3" type="text" size="20" maxlength="5" /> </p> <div id="LayerBotao"> <input name="simular" type="submit" value="Simular" class="Botao" /> </div> <p/> </form> <p> </p> <p> </p> <form action="" method="post" name="form1" class="style2"> <ul> <li> IVA incluido . </li> <li>Distancia Minima 45 k.m . </li> </ul> </form> <p> </p> <p> </p> <p> </p> </body> </html> Edited July 21, 2014 by rodrigolfm Link to comment Share on other sites More sharing options...
rodrigolfm Posted July 22, 2014 Author Report Share Posted July 22, 2014 (edited) Boas , não esta funcionando Edited June 29, 2015 by rodrigolfm Link to comment Share on other sites More sharing options...
N3lson Posted July 22, 2014 Report Share Posted July 22, 2014 dentro da função tens de declarar a variável $calcular12 function simular($x1,$x2){ global $calcular12 http://php.net/manual/en/language.variables.scope.php You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it. Link to comment Share on other sites More sharing options...
rodrigolfm Posted July 22, 2014 Author Report Share Posted July 22, 2014 (edited) Boas agora ja esta funcionando , de uma olhada e ve se tem como ser melhorado alguma coisa . mas é isso que eu queria . ainda estou ajustando os valores certos . 🙂 <?php //define as variaveis $txt_m3 = $_POST['txt_m3']; // Calcular o TXT_M3 if( $txt_m3 >= 1 && $txt_m3 <= 5 ){ $calcular12 = 1; //sim } elseif( $txt_m3 >= 6 && $txt_m3 <= 10 ){ $calcular12 = 2; //sim } elseif( $txt_m3 >= 11 && $txt_m3 <= 15 ){ $calcular12 = 3; //sim } elseif( $txt_m3 >= 16 && $txt_m3 <= 20 ){ $calcular12 = 4; //sim } else { $calcular12 = 0; // não } // FUNÇÃO SIMULAR ! function simular($x ,$x2, $calcular12 ){ if($calcular12 == 1) // confere se é até 20 m³ $v = ((1.40 * $x) + (1 * $x2)) * 23 / 100 + ((1.40 * $x) + (1 * $x2)) ; // + 23% DE IVA ! elseif($calcular12 == 2) // confere se é até 20 m³ $v = ((1.40 * $x) + (1.14 * $x2)) * 23 / 100 + ((1.40 * $x) + (1.14 * $x2)) ; // + 23% DE IVA ! elseif($calcular12 == 3) // confere se é até 20 m³ $v =((1.40 * $x) + (1.30 * $x2)) * 23 / 100 + ((1.40 * $x) + (1.30 * $x2)) ; // + 23% DE IVA ! elseif($calcular12 == 4) // confere se é até 20 m³ $v = ((1.40 * $x) + (1.45 * $x2)) * 23 / 100 + ((1.40 * $x) + (1.45 * $x2)) ; // + 23% DE IVA ! else $v = "<font color='red'> Desculpe ! Mas so Trasportamos até 20 m³ </font></<p/>"; return $v; } if ( isset($_POST['txt_km']) && $_POST['txt_km'] >= 45 ) { echo "<h1><font color='red'>Valor Total = € " .simular($_POST['txt_km'] ,$txt_m3, $calcular12) . "</font></h1><p/>"; } elseif( isset($_POST['txt_km']) && $_POST['txt_km'] < 45 ) echo "<h1><font color='red'> Distancia Curta , Minimo 45 km </font></h1><p/>"; ?> Edited June 29, 2015 by rodrigolfm Link to comment Share on other sites More sharing options...
N3lson Posted July 23, 2014 Report Share Posted July 23, 2014 como o valor de $_post tem de ser numerico eu alterava para isto isset($_POST['txt_km']) && is_numeric($_POST['txt_km']) && $_POST['txt_km'] >= 45 && is_numeric (....)) caso contrário verifica o erro se colocares uma letra You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it. Link to comment Share on other sites More sharing options...
rodrigolfm Posted July 24, 2014 Author Report Share Posted July 24, 2014 (edited) Boas , eu encontrei aguns erros no codigo e modifiquei. Obrigado <?php // FUNÇÃO SIMULAR ! function simular($x ,$x2 ){ $v = ((1.40 * $x) + (10 * $x2)) ; // EQUAÇÃO return $v; } if ( isset($_POST['txt_km' ]) && $_POST['txt_km'] < 10 ) { echo "<h1><font color='red'> Minimo 10 Km </font></h1><p/>"; } else echo "<h1><font color='red'>Valor Estimado = € " .simular($_POST['txt_km'] ,$_POST['txt_m3']) . "</font></h1><p/>"; ?> Edited June 29, 2015 by rodrigolfm Link to comment Share on other sites More sharing options...
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