Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Kalkulator PHP ciaglosc liczb
Forum PHP.pl > Forum > PHP
karolunited
Wiec robie sobie kalkulator w php,

Narzie jestem juz za tetapem ze gdzie nacisne np guzik "1" to mu wyskoczy "1", jezeli "2" to "2" itp

Teraz bym chcial ze jezeli nacisne "1" i "2" to mu wyskoczy "12" Tzn ciaglosc licz

  1. <?php
  2.  
  3.  
  4. if (isset($_GET['btn']))
  5. {
  6. switch ($_GET['btn'])
  7. {
  8. case 1:
  9. $myText1 = myAction($_GET['btn']);
  10. break;
  11. case 2:
  12. $myText1 = "2";
  13. break;
  14. case 3:
  15. $myText1 = "3";
  16. break;
  17. case 4:
  18. $myText1 = "4";
  19. break;
  20. case 5:
  21. $myText1 = "5";
  22. break;
  23. case 6:
  24. $myText1 = "6";
  25. break;
  26. case 7:
  27. $myText1 = "7";
  28. break;
  29. case 8:
  30. $myText1 = "8";
  31. break;
  32. case 9:
  33. $myText1 = "9";
  34. break;
  35. case dodawanie:
  36. $myText1 = "+";
  37. break;
  38. case odejmowanie:
  39. $myText1 = "-";
  40. break;
  41. case mnozenie:
  42. $myText1 = "*";
  43. break;
  44. case dzielenie:
  45. $myText1 = "/";
  46. break;
  47. case przecinek:
  48. $myText1 = ".";
  49. break;
  50. case 0:
  51. $myText1 = "0";
  52. break;
  53. case rowna:
  54. $myText1 = "=";
  55. break;
  56.  
  57. default:
  58. $myText1 = "0";
  59.  
  60. }
  61.  
  62. }
  63.  
  64. else {
  65. $myText1 =0;
  66.  
  67. }
  68.  
  69.  
  70. function myAction($myValue){
  71.  
  72. return $myValue;
  73. }
  74.  
  75.  
  76.  
  77. ?>
  78.  
  79. <center>
  80. <div style="position: absolute; width: 500px; margin-left: 50%; left: -250px;">
  81. <form action="Kalkulator23.php" method="get">
  82.  
  83. Kalkulator </br> </br></br>
  84.  
  85.  
  86. <input type="text" name="Text1" value="<?php echo $myText1; ?>" style=" width: 210px; float: left; margin-left: 140px;" />
  87. </br> </br>
  88. <button type="submit" name="btn" value="C" style="width: 210px;"> C </button>
  89. </br>
  90. <button type="submit" name="btn" value="1" style="width:50px;" > 1 </button>
  91. <button type="submit" name="btn" value="2" style="width:50px;" style="margin-left:10px"; > 2 </button>
  92. <button type="submit" name="btn" value="3" style="width:50px;" style="margin-left:10px"; > 3 </button>
  93. <button type="submit" name="btn" value="dodawanie" style="width:50px;" style="margin-left:10px"; > + </button>
  94. </br>
  95. <button type="submit" name="btn" value="4" style="width:50px;" style="margin:10px 0px 0px 10px;"; > 4 </button>
  96. <button type="submit" name="btn" value="5" style="width:50px;" style="margin-left:10px"; > 5 </button>
  97. <button type="submit" name="btn" value="6" style="width:50px;" style="margin-left:10px"; > 6 </button>
  98. <button type="submit" name="btn" value="odejmowanie" style="width:50px;" style="margin-left:10px"; > - </button>
  99. </br>
  100. <button type="submit" name="btn" value="7" style="width:50px;" style="margin-left:10px"; > 7 </button>
  101. <button type="submit" name="btn" value="8" style="width:50px;" style="margin-left:10px"; > 8 </button>
  102. <button type="submit" name="btn" value="9" style="width:50px;" style="margin-left:10px"; > 9 </button>
  103. <button type="submit" name="btn" value="mnozenie" style="width:50px;" style="margin-left:10px"; > * </button>
  104. </br>
  105. <button type="submit" name="btn" value="przecinek" style="width:50px;" style="margin-left:10px"; > , </button>
  106. <button type="submit" name="btn" value="0" style="width:50px;" style="margin-left:10px"; > 0 </button>
  107. <button type="submit" name="btn" value="rowna" style="width:50px;" style="margin-left:10px"; > = </button>
  108. <button type="submit" name="btn" value="dzielenie" style="width:50px;" style="margin-left:10px"; > / </button>
  109. </form>
  110. </div>
  111. </center>
Ilware
spróbuj wykorzystać java script i jquery

setTimeout();
onclick();

a dane przesyłaj ajax'em do php
Fifi209
Do wartości poprzedniej dopisz nową wartość jeżeli klinie z zakresu 0-9.

Co do działań matematycznych, będziesz musiał pamiętać o tym, że co z $_POST, $_GET to stringi. smile.gif
karolunited
Podpowiadali mi zeby petle zrobic, ale ktora mam wybrac.
Logicznie biorac to trzeba by bylo zrobic ze nacisne jaka liczbe, pozniej nastepna to petla robi ze do tej poprzednej liczby dodaje sie nowa i robi sie ciaglosc licz.

Moze mi ktos pomoc to zakumac ? dzieki wielkie
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.