2017-03-13 3 views
0

マイコード:Clickable calculatorこれを順番に行う方法は?

<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); 
} 
?> 

はどのようにそれを行うには? 例:

  • 私は1を、それを書き、それが2
  • 私は<button>1</button>をクリック書き、それが1
  • 私は<button>2</button>にクリック書き、それが1
  • 私は<button>1</button>をクリックし、書き込み、<button>1</button>をクリック

など....

は次のようになります。

私はそれは、彼らがクリックされたのと同じ順番で書いているクリックすると。

ありがとうございます。

+0

はPHPで(またはそれが何であれ)*電卓*を構築するためのナンセンスではないですか? –

+0

これは非常にばかげたやり方です – RiggsFolly

答えて

0

あなたは正確に何をしようとしていますか?あなたが値を追加し、それらをリセットすることができます電卓のようなものを作りたい場合は、次のことをしようとしない理由:

  1. の値TOTクリックされたボタンの値を追加します。
  2. ファイルの内容を読みますファイル
  3. 結果をファイルに保存
  4. リピート

しかし、そんなにうまくいけば、電卓を電卓に書くのはどうですか?これに代えて

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"); 
} 
関連する問題