本文目錄一覽:
求一個抽獎系統不要轉盤的,php的,寫好注釋
前台頁面:
!DOCTYPE html
html
head
meta charset=”utf8″ /!–頁面編碼方式–
title抽獎系統/title
/head
style type=”text/css”
#result { color:red; padding-top:10px; }
/style
script src=”
script type=”text/javascript”
$(document).ready(function(){
$(“#lottery”).click(function(){
$.ajax({
url: ‘handle.php’,//請求結果頁
type: ‘POST’,//請求方式
data:{info:$(“#info”).val()},//傳送用戶信息
dataType: ‘html’,//傳輸數據類型格式
success: function(response){
$(“#result”).html(response);//顯示返回結果
}
});
});
});
function submit(){
return false;//不處理默認提交請求,走ajax請求。
}
/script
body
form action=”javascript:submit();” method=”post”
table
tr
input type=”hidden” value=”personinfo” name=”info” id=”info”/!–隱藏字段,表示用戶,可以換成用戶的信息–
tdlabel for=”lottery”抽獎/label/td
tdinput id=”lottery” type=”submit” name=”lottery” value=”點擊幸運抽獎”/td
/tr
tr
td colspan=”2″ id=”result”/td!–通過ajax展示結果–
/tr
/table
/form
/body
/html
後台處理頁面:
?php
header(“Content-type:text/html;charset=utf-8”);
$info = $_POST[“info”];//接受用戶標識,以後保存到數據庫
$rand = rand(1,10); //從1-10中隨機取出一個數字,這裡可以自己調整範圍,如果為1,100 那麼中獎率就大致為1/100.
if($rand==5){//如果等於5,就中獎了,這裡隨便設置一個數就行
echo “恭喜你中獎了!”;
} else {
echo “抱歉,下次加油!”;
}
?
如有疑問,請追問。
php抽獎系統怎麼設計
用戶進入抽獎頁面的時候,已經通過概率計算出他的獎品。
然後將獎品告訴前端,用戶點開始的時候,讓js老老實實跳到該獎品上即可。
PHP設置抽獎系統問題?
加個字段,抽完改掉哪個字段的值。用tinyint就可以了。設0和1就可以。
你說的那同時一張的情況不會出現。mysql執行有先後順序。
原創文章,作者:PUFVL,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/128466.html