LoginSignup
2
1

More than 3 years have passed since last update.

webプログラミング演習ノート 3回目(3限)

Last updated at Posted at 2019-10-08

webプログラミング演習 2019/10/8

復習から

/lesson3/form.phpにアクセスして formをつくり数字をいれて結果をresult.phpに出力する。/

  • 3の倍数の場合 Foo
  • 5の倍数の場合 Bar
  • 15の倍数の場合FooBar

と出力する。

わからない人は モジュル演算 phpとかで調べるといいよと言われました。

やり方がわからなかったのでリサーチして参考にしたのは何故かJSの記事草 ここ

result.phpにはこんな感じで書きました。

result.php
<?
$val = ['value']

    if( $val % 3 == 0 ){
        echo "Foo<br />";
    }
    if( $val % 5 == 0 ){
        echo "Bar<br />";
    }
    if( $val % 15 == 0 ){
        echo "FooBar<br />";
    }
?>  

こっちはform.php↓

form.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>webプログラミングむずいよ</title>
</head>
<body>
<form action="/lesson3/result.php" method="POST">
<input type="text" name="value1" value="0" />
    <button value='foobar'>ボタン</button>
</form>

</body>
</html>

絶対違うけどこれで動いてしまった、そして先生の模範解答は・・・

まずはform.phpの方から

form.php

<!DOCTYPE html>
<html><body>
<form action="/lesson3/result.php" method="POST"></form>
<input type="text" name="number">
<button>ボタン</button>    
</body>
</html>

そしてこっちがresult.php

result.php
<?
$num = $_POST['number'];
$msg = '';
if($num %3 == 0){
    $msg = 'Foo';
}
if($num %5 == 0){
    $msg = 'Bar';
}
if($num %15 == 0){
    $msg = 'FooBar';
}
?>

いきなり「はい、15分でやってくださーい」と言われて焦ったけどもなんとかそれっぽくできた!
まだ舞える

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1