![]() |
PCDVD數位科技討論區
(https://www.pcdvd.com.tw/index.php)
- 疑難雜症區
(https://www.pcdvd.com.tw/forumdisplay.php?f=34)
- - php,submit後,如何將亂數值固定
(https://www.pcdvd.com.tw/showthread.php?t=672658)
|
|---|
php,submit後,如何將亂數值固定
功能:
產生一個亂數 用這個亂數當猜數字的題目 猜的如果比亂數小,印出:太小了 猜的如果比亂數大,印出:太大了 猜的如果等於亂數,印出:right 問題: 每按一次submit 亂數就會變一次.... 我要的功能是產生一個亂數後 就一直以那個亂數去猜大小 不能每按一次submit後亂數又變更 該怎麼解決? -------------------------------------- <html> <head> <title></title> </head> <body> <CENTER> <form method="post"> 請輸入搜尋的數字:<input type=text name=n> <input type=submit value=送出> </form> </CENTER> <hr> <? $num=rand(1,100); echo $num; if (isset($n)) { if ($n<$num) { echo "太小了"; continue; } elseif ($n>$num) { echo "太大了"; continue; } else { echo "right"; } } ?> </body> </HTML> |
引用:
你要把產生的那個亂數, 存入 session 或 cookie 再去比較. 照你這樣寫, 當然你每次按 submit 他就會產生一個 random 數目 |
| 所有的時間均為GMT +8。 現在的時間是07:12 PM. |
vBulletin Version 3.0.1
powered_by_vbulletin 2026。