tworzona jest tablica z kolejną cyfrą. Następnie cyfry są wyświetlane przez plik kalkulator.php. Niestety po każdym wciśniętym przycisku tablica się zeruje i pokazuje tylko jedną, ostatnią cyfrę zamiast dodawać kolejne elementy do tej tablicy i wtedy wyświetlać.
Oto pliki:
kalk.php
<?php if ($_GET['wynik'] == "1") { } if ($_GET['wynik'] == "2") { } } else { } include 'kalkulator.php'; ?>
kalkulator.php
<?php require_once ('kalk.php'); ?> <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <title>KALKULATOR</title> <meta name='viewport' content='width=device-width, initial-scale=1'> <link rel='stylesheet' type='text/css' media='screen' href='main1.css'> <script src='main.js'></script> </head> <body> <table class="tabela"> <tr> <td colspan="4" class="wyswietlacz"> Działanie: <?php foreach ($liczby as $cyfra) { } ?> <br> Wynik: </td> </tr> <tr> <td> <form action="kalk.php" method="get"> <input type=submit value="1" class="input"/> <input type="hidden" name="wynik" value= "1" /> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="2" class="input"/> <input type="hidden" name="wynik" value="2" /> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="3" class="input"/> <input type="hidden" name="wynik" value="3" ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="C" class="input"/> <input type="hidden" name="wynik" value="C" ?> <input type="hidden" name="zn" value="kasowanie"/> </form> </td> </tr> <tr> <td> <form action="kalk.php" method="get"> <input type=submit value="4" class="input"/> <input type="hidden" name="wynik" value="4" ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="5" class="input"/> <input type="hidden" name="wynik" value="5" ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="6" class="input"/> <input type="hidden" name="wynik" value="6" ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="-" class="input"/> <input type="hidden" name="wynik" value="-" ?> <input type="hidden" name="zn" value="minus"/> </form> </td> </tr> <tr> <td> <form action="kalk.php" method="get"> <input type=submit value="7" class="input"/> <input type="hidden" name="wynik" value="7" ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="8" class="input"/> <input type="hidden" name="wynik" value="8" ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="9" class="input"/> <input type="hidden" name="wynik" value="9" ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="+" class="input"/> <input type="hidden" name="wynik" value="+" ?> <input type="hidden" name="zn" value="plus"/> </form> </td> </tr> <tr> <td> <form action="kalk.php" method="get"> <input type=submit value="." class="input"/> <input type="hidden" name="wynik" value="." ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="/" class="input"/> <input type="hidden" name="wynik" value="/" ?> <input type="hidden" name="zn" value="dzielenie"/> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="0" class="input"/> <input type="hidden" name="wynik" value="0" ?> </form> </td> <td> <form action="kalk.php" method="get"> <input type=submit value="=" class="input"/> <input type="hidden" name="wynik" value="=" ?> <input type="hidden" name="zn" value="rowna"/> </form> </td> </tr> <tr> <td> <form action="kalk.php" method="get"> <input type=submit value="*" class="input"/> <input type="hidden" name="wynik" value="*" ?> <input type="hidden" name="zn" value="mnozenie"/> </form> </td> <td> <form> <input type=submit value=" " class="input"/> </form> </td> <td> <form> <input type=submit value=" " class="input"/> </form> </td> <td> <form> <input type=submit value=" " class="input"/> </form> </td> </tr> </table> </body> </html> </html>
main1.css
.tabela { padding:0; border:1px solid black; } tr { padding: 3px; } td { padding: 3px; } .input{ width:40px; height:40px; background-color: blue; border:0; color:white; font-size:20px; border-radius:5px; } input:hover { background-color:purple; } .wyswietlacz{ height:40px; padding:5px; background-color: rgb(93, 93, 214); color:white; font-size:15px; }