总结
豆包 AI 助手文章总结

PHP滚动抽奖代码

不言
发布: 2018-04-26 09:17:11
原创
2543人浏览过


这篇文章介绍的内容是关于php滚动抽奖代码,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

页面:

 

<table style="width: 100%"   cellpadding="2" cellspacing="1" border="0">
		<colgroup>
			<col style="width: 30%"/>
			<col style="width: 70%"/>
		</colgroup>
		<tr>
			<td colspan="2" style="text-align: center">
				<br>
			</td>
		</tr>
		<tr style="display: none;" id="content" >
			<td colspan="2" style="font-size:40px;text-align: center;">
				<p  id="roll" style="width:100%;height:50%;font-weight: bold;margin-top:7.1%">

				</p>
			</td>
		</tr>
		<tr id="imgbut">
			<td colspan="2" style="text-align: center" >
				<p style="height: 50%">
					@@##@@
				</p>
			</td>
		</tr>
</table>
登录后复制

js代码:

<script type="text/javascript">
	$(function(){
		var _gogo;
		var start_btn = $("#start");
		start_btn.click(function(){
			time=0;
			$.getJSON('/oa/public/index.php/staffinfo/question/getdata/',function(json){
				if(json){
					var obj = eval(json);//将JSON字符串转化为对象
					var len = obj['ids'].length;
					_gogo = setInterval(function(){
						var numrand = getRandomArrayElements(obj['ids'],5);//获取随机数
						var text='';
						time+=1;
						for (var i=0;i<numrand.length;i++)
						{
							text+='<span class="realname" style="margin-left: 25%;float: left;color: 2a475c;">'+obj['question'][numrand[i]]['realname']+'</span><span class="phone" style="margin-right: 25%; float: right;color: orangered;">    '+obj['question'][numrand[i]]['phone']+"</span><br><br>"
						}
						$("#roll").html(text);
						if(time>500){
							clearInterval(_gogo);
						}
					},1); //每隔0.1秒执行一次
					start_btn.hide();
					$("#content").css('display','');
				}else{
					$("#roll").html('系统找不到数据源,请先导入数据。');
				}
			});
		});
	});
	function getRandomArrayElements(arr, count) {
		var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
		while (i-- > min) {
			index = Math.floor((i + 1) * Math.random());
			temp = shuffled[index];
			shuffled[index] = shuffled[i];
			shuffled[i] = temp;
		}
		return shuffled.slice(min);
	}

</script>
登录后复制

控制器:

立即学习PHP免费学习笔记(深入)”;

 

public function tvshowAction(){
		$prize = $this->_request->get('prize');
		$this->view->prize=$prize;
	}
public  function getdataAction() {
		global $db;
		$ids = $db->fetchCol('SELECT id FROM oa_user_question WHERE id IN (SELECT min(id) FROM oa_user_question GROUP BY phone) and is_show=1; ');
		$questions = $db->fetchAll('select * from oa_user_question where is_show=1');
		$arr=array();
		foreach($questions as $question){
			$question['realname']=mb_strlen($question['realname'])>8?(substr($question['realname'],0,8).'...'):$question['realname'];
			$question['realname']=iconv('gbk', 'utf-8', $question['realname']);
			foreach($ids as $id){
				if($question['id']==$id){
					$arr[$id]=$question;
				}
			}
		}
		$result=array(
			'ids'=>$ids,
			'question'=>$arr
		);
		echo json_encode($result );
		die;
	}
登录后复制

相关推荐:

PHP滚动日志的代码实现

PHP滚动抽奖代码

以上就是PHP滚动抽奖代码的详细内容,更多请关注php中文网其它相关文章!

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号