Кликабельный калькулятор, как это сделать в последовательности?

Мой код:

<form method="get">
<button name="one" value="1">1</button>
<button name="two" value="2">2</button>
</form><?php
$count=file_get_contents('count.txt');
$count++;
file_put_contents('count.txt',$count);$one=$_GET['one'] ?? NULL;
$two=$_GET['two'] ?? NULL;if($one && $count==1){

file_put_contents('one1.txt',$one);
}

if($one && $count==2){
file_put_contents('one2.txt',$one);
}

if($one && $count==3){
file_put_contents('one3.txt',$one);
}

if($one && $count==4){
file_put_contents('one4.txt',$one);
}
if($one && $count==5){
file_put_contents('one5.txt',$one);
}

if($one && $count==6){
file_put_contents('one6.txt',$one);
}
//----------------------------------------

if($two && $count==1){
file_put_contents('two1.txt',$two);
}
if($two && $count==2){
file_put_contents('two2.txt',$two);
}

if($two && $count==3){
file_put_contents('two3.txt',$two);
}

if($two && $count==4){
file_put_contents('two4.txt',$two);
}

if($two && $count==5){
file_put_contents('two5.txt',$two);
}
if($two && $count==6){
file_put_contents('two6.txt',$two);
}

echo file_get_contents('one1.txt');
echo file_get_contents('one2.txt');
echo file_get_contents('one3.txt');
echo file_get_contents('one4.txt');
echo file_get_contents('one5.txt');
echo file_get_contents('one6.txt');

echo file_get_contents('two1.txt');
echo file_get_contents('two2.txt');
echo file_get_contents('two3.txt');
echo file_get_contents('two4.txt');
echo file_get_contents('two5.txt');
echo file_get_contents('two6.txt');
?>

<form>
<input type="submit" name="reset"/>
</form>

<?php
if($_GET['reset'] ?? NULL){
file_put_contents('one1.txt',false);
file_put_contents('one2.txt',false);
file_put_contents('one3.txt',false);
file_put_contents('one4.txt',false);
file_put_contents('one5.txt',false);
file_put_contents('one6.txt',false);

file_put_contents('two1.txt',false);
file_put_contents('two2.txt',false);
file_put_contents('two3.txt',false);
file_put_contents('two4.txt',false);
file_put_contents('two5.txt',false);
file_put_contents('two6.txt',false);

file_put_contents('count.txt',false);
}
?>

Как это сделать?
Пример:

  • Я нажимаю <button>1</button>напиши 1
  • Я нажимаю <button>1</button>напиши 1
  • Я нажимаю <button>2</button>напиши это 2
  • Я нажимаю <button>1</button>напиши 1

так далее….

Должно быть:

  • 1121

Когда я нажимаю, пишите в том же порядке, в котором они нажимали.

Заранее спасибо.

0

Решение

Что именно ты пытаешься сделать? Если вы хотите создать своего рода калькулятор, который может добавлять значения и сбрасывать их, почему бы не попробовать следующее:

  1. Прочитайте содержание вашего файла
  2. Добавьте значение нажатой кнопки к значению файла
  3. Запишите результат в файл
  4. повторение.

Но как же там лучше, чем написать калькулятор на php?

0

Другие решения

Вместо этого:

echo file_get_contents('one1.txt');
echo file_get_contents('one2.txt');
echo file_get_contents('one3.txt');
echo file_get_contents('one4.txt');
echo file_get_contents('one5.txt');
echo file_get_contents('one6.txt');

echo file_get_contents('two1.txt');
echo file_get_contents('two2.txt');
echo file_get_contents('two3.txt');
echo file_get_contents('two4.txt');
echo file_get_contents('two5.txt');
echo file_get_contents('two6.txt');

Это:

for($i=1;$i<=6;$i++) {
echo file_get_contents("one$i.txt");
echo file_get_contents("two$i.txt");
}
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector