分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

php做投票题目

发布时间:2023-09-06 01:37责任编辑:熊小新关键词:暂无标签

1. 做一个类DBDA 把数据库内容封装进去

<?phpclass DBDA{ ???public $host="localhost"; //服务器地址 ???public $uid="root"; //用户名 ???public $pwd="5270437"; //密码 ???public $dbname="ceshi"; //数据库名称 ???????/* ???????执行一条SQL语句的方法 ???????@param sql 要执行的SQL语句 ???????@param type SQL语句的类型,0代表查询 1代表增删改 ???????@return 如果是查询语句返回二维数组,如果是增删改返回true或false ???*/ ???public function query($sql,$type=0){ ???????$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname); ???????$result = $db->query($sql); ???????if($type){ ???????????return $result; ???????}else{ ???????????return $result->fetch_all(); ???????} ???}}

2.做一个数据访问页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body><h1>投票页面</h1><form action="chakantoupiaojieguo.php" method="post"><?php ???require_once "./DBDA.class.php"; ???$db = new DBDA(); ???$sql = "select * from diaoyantimu"; ???$arr = $db->query($sql); ???foreach($arr as $v){ ???????echo "<div>{$v[1]}</div>"; ???????$sqlxx = "select * from diaoyanxuanxiang where timudaihao=‘{$v[0]}‘"; ???????$arrxx = $db->query($sqlxx); ???????foreach($arrxx as $vxx){ ???????????echo "<div><input type=‘checkbox‘ name = ‘ck[]‘ value=‘{$vxx[0]}‘/>{$vxx[1]}</div>"; ???????} ???}?><input type="submit" value="投票" /></form></body></html>

3.做一个处理投票的页面

<?php ???$arr = $_POST["ck"]; ???//var_dump($arr); ???require_once "./DBDA.class.php"; ???$db = new DBDA(); ???$str = implode("‘,‘",$arr); ???$sql = "update diaoyanxuanxiang set numbers = numbers+1 where ids in(‘{$str}‘) "; ???$reslut = $db->query($sql,1); ???if($reslut){ ???????header("location:toupiaochakan.php"); ???}else{ ???????echo "投票失败!"; ???}?>

4.投票的查看页面跳出百分比

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css">.wai{width:200px; height:10px; border:1px solid #F00}.nei{height:10px; float:left; background-color:#F00}</style></head><body><h1>投票结果显示</h1><?php ???require_once "./DBDA.class.php"; ???$db = new DBDA(); ???$sql = "select * from diaoyantimu"; ???$arr = $db->query($sql); ???foreach($arr as $v){ ???????echo "<div>{$v[1]}</div>"; ???????$sqlall ?= "select sum(numbers) from diaoyanxuanxiang where timudaihao=‘{$v[0]}‘"; ???????$arrall = $db->query($sqlall); ???????$sqlxx = "select * from diaoyanxuanxiang where timudaihao=‘{$v[0]}‘"; ???????$arrxx = $db->query($sqlxx); ???????foreach($arrxx as $vxx){ ???????????$vxx[2]; ???????????$arrall[0][0]; ???????????$bfb = ($vxx[2]/$arrall[0][0])*100; ???????????echo "<div>{$vxx[1]}<div class=‘wai‘><div class=‘nei‘ style=‘width:{$bfb}%‘></div></div>{$bfb}%{$vxx[2]}</div>"; ???????} ???}?></body></html>

php做投票题目

原文地址:https://www.cnblogs.com/palpitate/p/8316116.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved