php+js随机抽奖程序
2011-10-26 15:21
531 查看
<?php header('Content-Type: text/html; charset=utf-8'); include_once('../source/init.php'); include_once('./include.php'); $sql = "SELECT username FROM eg_mnd_quiz WHERE status='2'"; $rs = $db->query($sql) ; $lucks = array() ; while( $row = $db->fetch_array($rs) ) { $lucks[]=$row['username'] ; } $luckstr=implode(',',$lucks); echo '抽奖名单:<br><br>',$luckstr; ?> <html> <title>随机抽奖</title> <head> <meta http-equiv=Content-Type content="text/html;charset=utf-8"> </head> <body> <SCRIPT LANGUAGE="JavaScript"> var alldata = "<?php echo $luckstr;?>" //php后台数据,以逗号分隔 var alldataarr = alldata.split(",") var num = alldataarr.length-1 var randnum var timer function change(){ document.getElementById('oknum-1').value = alldataarr[GetRnd(0,num)]; document.getElementById('oknum-2').value = alldataarr[GetRnd(0,num)]; document.getElementById('oknum-3').value = alldataarr[GetRnd(0,num)]; } function start(){ clearInterval(timer); timer = setInterval('change()',36); //随机数据变换速度,越小变换的越快 } function ok(){ //noDupNum(); clearInterval(timer); } function GetRnd(min,max){ randnum = parseInt(Math.random()*(max-min+1)); return randnum; } function noDupNum(){ // to remove the selected mobile phone number alldataarr.removeEleAt(randnum); // to reorganize the mobile number array!! var o = 0; for(p=0; p<alldataarr.length;p++){ if(typeof alldataarr[p]!="undefined"){ alldataarr[o] = alldataarr[p]; o++; } } num = alldataarr.length-1; } // method to remove the element in the array Array.prototype.removeEleAt = function(dx) { if(isNaN(dx)||dx>this.length){return false;} this.splice(dx,1); } </SCRIPT> <br/><br/><br/><br/><br/> <input type="text" id="oknum-1" name="oknum-1" value="" readonly> <button id='b1' onclick="start();disabled=true;b2.disabled=false;" accesskey="s">开始抽奖(<U>S</U>)</button> <button id='b2' onclick="ok();disabled=true;b1.disabled=false;" accesskey="o">停止(<U>O</U>)</button> </body> </html>
相关文章推荐
- 适用于抽奖程序、随机广告的PHP概率算法实例
- 基于PHP实现简单的随机抽奖小程序
- 适用于抽奖程序 随机广告的PHP概率算法实例
- 基于PHP实现简单的随机抽奖小程序
- 适用于抽奖程序、随机广告的PHP概率算法实例
- js随机抽奖程序
- PHP翻转抽奖程序
- js小抽奖程序
- PHP概率算法(适用于抽奖、随机广告)
- 基于JavaScript实现简单的随机抽奖小程序
- php编写的抽奖程序中奖概率算法
- 使用jQuery+PHP+Mysql实现抽奖程序
- 使用jQuery+PHP+Mysql实现抽奖程序
- 分享一个PHP抽奖算法程序代码
- 一个好玩的jq+php实现转盘抽奖程序
- 幸运大转盘-jQuery+PHP实现的抽奖程序(上)
- 使用jQuery+PHP+Mysql实现抽奖程序
- 幸运大转盘-jQuery+PHP实现的抽奖程序(下)
- js小抽奖程序
- php实现概率性随机抽奖代码