Board logo

標題: 20110709投票系統 [打印本頁]

作者: may    時間: 2011-7-9 21:40     標題: 20110709投票系統

index.php
vote.php
look_vote.php
look_vote_ok.php
conn/conn.php
sql.php
作者: may    時間: 2011-7-9 21:41

conn/conn.php

<?php
$conn=mysql_connect("localhost","root","3893527") or die('連接失敗:' . mysql_error());
if(mysql_select_db("db_vote",$conn))
  echo "";
  else
  echo ('數據庫選擇失敗:' . mysql_error());
mysql_query("set names utf8");
?>
作者: may    時間: 2011-7-9 21:42

sql.php

-- phpMyAdmin SQL Dump
-- version 2.10.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 03, 2011 at 12:09 AM
-- Server version: 5.0.51
-- PHP Version: 5.2.6

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `db_vote`
--

-- --------------------------------------------------------

--
-- Table structure for table `tb_vote`
--

CREATE TABLE `tb_vote` (
  `tb_vote_id` int(5) NOT NULL auto_increment,
  `tb_vote_name` varchar(50) NOT NULL,
  `tb_vote_num` int(5) NOT NULL default '0',
  `tb_vote_type` int(1) NOT NULL default '0',
  PRIMARY KEY  (`tb_vote_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=26 ;

--
-- Dumping data for table `tb_vote`
--

INSERT INTO `tb_vote` VALUES (25, '那些東西是您喜歡的?', 6, 1);
INSERT INTO `tb_vote` VALUES (24, '總統大選您會投誰?', 3, 0);

-- --------------------------------------------------------

--
-- Table structure for table `tb_voter`
--

CREATE TABLE `tb_voter` (
  `tb_voter_id` int(10) NOT NULL auto_increment,
  `tb_voter_name` varchar(50) NOT NULL,
  `tb_voter_pass` varchar(50) NOT NULL,
  `tb_voter_activation` text NOT NULL,
  `tb_voter_mail` varchar(80) NOT NULL,
  `tb_voter_tel` varchar(50) NOT NULL,
  `tb_voter_address` varchar(80) NOT NULL,
  `tb_voter_ip` varchar(50) NOT NULL,
  `tb_voter_type` varchar(50) NOT NULL,
  PRIMARY KEY  (`tb_voter_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=78 ;

--
-- Dumping data for table `tb_voter`
--

INSERT INTO `tb_voter` VALUES (68, 'fdddf', 'e940a3ba6df738388b772344a8a112e4', 'http://127.0.0.1/MR/sl/11/13/register_ok.php?name=4ed68f3009bd25ed96d236cb956250db&&pass=e940a3ba6df738388b772344a8a112e4', 'sp@mrbccd.com', '13604338', 'dsfdsfdsf', '127.0.0.1', '1');
INSERT INTO `tb_voter` VALUES (67, 'sdfsdf', 'ec37aa25501f5aea74d5eb3d19b08333', 'http://127.0.0.1/MR/sl/11/13/register_ok.php?name=d58e3582afa99040e27b92b13c8f2280&&pass=ec37aa25501f5aea74d5eb3d19b08333', 'spcn@mrbccd.com', '13604338', 'sdfdsfs', '127.0.0.1', '0');
INSERT INTO `tb_voter` VALUES (66, 'sddsfsd', '013f890e35d1b7f5e45f21e60f7863d6', 'http://127.0.0.1/MR/sl/11/13/register_ok.php?name=6df9626d17c2f0135899ec71b43b3d42&&pass=013f890e35d1b7f5e45f21e60f7863d6', 'spcn@mrbccd.com', 'sddsds', 'sddsds', '127.0.0.1', '0');
INSERT INTO `tb_voter` VALUES (65, 'dsfdsf', '6fbfd5e68d3306e51350bea0232f8fa5', 'http://127.0.0.1/MR/sl/11/13/register_ok.php?name=d6e9c56d7f078d298ed4695d899effbe&&pass=6fbfd5e68d3306e51350bea0232f8fa5', 'pankaihua1103@mrbccd.com', 'sdfsd', 'sdfdss', '127.0.0.1', '0');
INSERT INTO `tb_voter` VALUES (64, 'fghfg', 'c1ebb4933e06ce5617483f665e26627c', 'http://127.0.0.1/MR/sl/11/13/register_ok.php?name=b0069c74a975f155fb785aa954de7562&&pass=c1ebb4933e06ce5617483f665e26627c', 'pankaihua1103@mrbccd.com', 'dfsdf', 'dfdf', '127.0.0.1', '0');
INSERT INTO `tb_voter` VALUES (62, 'sdfds', 'ec37aa25501f5aea74d5eb3d19b08333', 'http://127.0.0.1/MR/sl/11/13/register_ok.php?name=6fbfd5e68d3306e51350bea0232f8fa5&&pass=ec37aa25501f5aea74d5eb3d19b08333', 'pankaihua1103@mrbccd.com', 'ddd', 'dddd', '127.0.0.1', '0');
INSERT INTO `tb_voter` VALUES (63, 'sdfds', '3ae5e9658fbd7d4048bd40820b7d227d', 'http://127.0.0.1/MR/sl/11/13/register_ok.php?name=6fbfd5e68d3306e51350bea0232f8fa5&&pass=3ae5e9658fbd7d4048bd40820b7d227d', 'pankaihua1103@mrbccd.com', 'ddd', 'dddd', '127.0.0.1', '0');
INSERT INTO `tb_voter` VALUES (61, 'dfs', 'd58e3582afa99040e27b92b13c8f2280', 'http://127.0.0.1/MR/sl/11/12/register_ok.php?name=4ec503be252d765ea37621a629afdaa6&&pass=d58e3582afa99040e27b92b13c8f2280', 'pankaihua1103@mrbccd.com', 'sdfds', 'sdfds', '127.0.0.1', '0');
INSERT INTO `tb_voter` VALUES (60, '溜溜', '202cb962ac59075b964b07152d234b70', 'http://192.168.1.59/MR/sl/06/12/register_ok.php?name=7b8816485f8a15230957fe4039b648c0&&pass=202cb962ac59075b964b07152d234b70', 'spcn@mrbccd.com', '13604338', '長春市', '192.168.1.59', '1');
INSERT INTO `tb_voter` VALUES (59, '潘華', '698d51a19d8a121ce581499d7b701668', 'http://192.168.1.59/MR/sl/06/12/register_ok.php?name=0e77083a5e2fa59da6f289e7f2eb6725&&pass=698d51a19d8a121ce581499d7b701668', 'spcn@mrbccd.com', '1360433', '長春市', '192.168.1.59', '1');
INSERT INTO `tb_voter` VALUES (69, '123456', 'e10adc3949ba59abbe56e057f20f883e', 'http://127.0.0.1/MR/sl/11/13/register_ok.php?name=e10adc3949ba59abbe56e057f20f883e&&pass=e10adc3949ba59abbe56e057f20f883e', 'sp@mrbccd.com', '13604338784', 'sdfsdfsdf', '127.0.0.1', '1');
INSERT INTO `tb_voter` VALUES (70, 'sdfsdfsdf', '733540828109ecc5c86ff7fb515e6c4c', 'http://192.168.1.59/MR/11/13/register_ok.php?name=73a90acaae2b1ccc0e969709665bc62f&&pass=733540828109ecc5c86ff7fb515e6c4c', 'dfd@mrbccd.com', '1360433', 'dfgdfgdf', '192.168.1.59', '0');
INSERT INTO `tb_voter` VALUES (71, 'sdfsd', 'd58e3582afa99040e27b92b13c8f2280', 'http://192.168.1.59/MR/11/13/register_ok.php?name=84d9cfc2f395ce883a41d7ffc1bbcf4e&&pass=d58e3582afa99040e27b92b13c8f2280', 'sfdfdfn@mrbccd.com', '13604338', 'sdfsdfds', '192.168.1.59', '0');
INSERT INTO `tb_voter` VALUES (72, 'sdfsdf', '726784b1a8c22c54054674ef3bdb4153', 'http://192.168.1.59/MR/11/13/register_ok.php?name=d58e3582afa99040e27b92b13c8f2280&&pass=726784b1a8c22c54054674ef3bdb4153', 'sfdfdfn@mrbccd.com', '1360433', 'sdfsdfds', '192.168.1.59', '0');
INSERT INTO `tb_voter` VALUES (73, 'sdfsdf', 'aaec21a67e5619f786c4c84349cba673', 'http://192.168.1.59/MR/11/13/register_ok.php?name=d58e3582afa99040e27b92b13c8f2280&&pass=aaec21a67e5619f786c4c84349cba673', 'sfdfdfn@mrbccd.com', '1360433', 'sdfsdfds', '192.168.1.59', '0');
INSERT INTO `tb_voter` VALUES (74, 'mrosft', '698d51a19d8a121ce581499d7b701668', 'http://192.168.1.59/MR/11/02/register_ok.php?name=bee3ffc488f8b859d981e8c1ae697941&&pass=698d51a19d8a121ce581499d7b701668', 'sp@mrbccd.com', '1360433', '長春市', '192.168.1.59', '0');
INSERT INTO `tb_voter` VALUES (75, 'mrosft', '698d51a19d8a121ce581499d7b701668', 'http://192.168.1.59/MR/11/02/register_ok.php?name=bee3ffc488f8b859d981e8c1ae697941&&pass=698d51a19d8a121ce581499d7b701668', 'sp@mrbccd.com', '1360433', '長春市', '192.168.1.59', '0');
INSERT INTO `tb_voter` VALUES (76, 'mrosft', '698d51a19d8a121ce581499d7b701668', 'http://192.168.1.59/MR/11/02/register_ok.php?name=bee3ffc488f8b859d981e8c1ae697941&&pass=698d51a19d8a121ce581499d7b701668', 'sp@mrbccd.com', '1360433', '長春市', '192.168.1.59', '0');
INSERT INTO `tb_voter` VALUES (77, 'yaohuaq', 'e10adc3949ba59abbe56e057f20f883e', 'http://localhost/mr/11/02/register_ok.php?name=d52064aaa0e90285ac410341a5f8ae16&&pass=e10adc3949ba59abbe56e057f20f883e', 'yaohuaq@mr.com', '0431-84978981', 'china', '127.0.0.1', '0');

-- --------------------------------------------------------

--
-- Table structure for table `tb_vote_more`
--

CREATE TABLE `tb_vote_more` (
  `tb_vote_id` int(10) NOT NULL auto_increment,
  `tb_vote_subject` varchar(80) NOT NULL,
  `tb_vote_content` mediumtext NOT NULL,
  `tb_vote_counts` varchar(50) NOT NULL,
  `tb_vote_type` varchar(50) NOT NULL,
  `tb_vote_explain` mediumtext NOT NULL,
  `tb_vote_photo` varchar(80) NOT NULL,
  PRIMARY KEY  (`tb_vote_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

--
-- Dumping data for table `tb_vote_more`
--

INSERT INTO `tb_vote_more` VALUES (1, '優秀負責人', '喬伊', '100', '多選', '', '');
INSERT INTO `tb_vote_more` VALUES (2, '優秀負責人', '薛嶽', '104', '多選', '', '');
INSERT INTO `tb_vote_more` VALUES (3, '優秀負責人', '劉易', '75', '多選', '', '');
INSERT INTO `tb_vote_more` VALUES (4, '優秀負責人', '金一', '78', '多選', '', '');
INSERT INTO `tb_vote_more` VALUES (5, '優秀負責人', '梁毅', '90', '多選', '', '');
INSERT INTO `tb_vote_more` VALUES (6, '優秀負責人', '董一', '70', '多選', '', '');
INSERT INTO `tb_vote_more` VALUES (7, '優秀負責人', '寇一', '96', '多選', '', '');

-- --------------------------------------------------------

--
-- Table structure for table `tb_vote_more_ip`
--

CREATE TABLE `tb_vote_more_ip` (
  `tb_vote_ip_id` int(10) NOT NULL auto_increment,
  `tb_vote_subject` varchar(80) NOT NULL,
  `tb_vote_ip` varchar(50) NOT NULL,
  PRIMARY KEY  (`tb_vote_ip_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=25 ;

--
-- Dumping data for table `tb_vote_more_ip`
--

INSERT INTO `tb_vote_more_ip` VALUES (1, '優秀負責人', '127.0.0.1');
INSERT INTO `tb_vote_more_ip` VALUES (2, '優秀負責人', '192.168.1.59');
INSERT INTO `tb_vote_more_ip` VALUES (3, '優秀負責人', '192.168.1.59');
INSERT INTO `tb_vote_more_ip` VALUES (4, '優秀負責人', '192.168.1.59');
INSERT INTO `tb_vote_more_ip` VALUES (24, '優秀負責人', '10.9.1.65');
INSERT INTO `tb_vote_more_ip` VALUES (23, '優秀負責人', '10.9.1.65');
INSERT INTO `tb_vote_more_ip` VALUES (22, '優秀負責人', '10.9.1.65');

-- --------------------------------------------------------

--
-- Table structure for table `tb_vote_odd`
--

CREATE TABLE `tb_vote_odd` (
  `tb_vote_id` int(10) NOT NULL auto_increment,
  `tb_vote_subject` varchar(80) NOT NULL,
  `tb_vote_content` varchar(80) NOT NULL,
  `tb_vote_counts` varchar(50) NOT NULL,
  `tb_vote_type` varchar(50) NOT NULL,
  `tb_vote_photo` varchar(80) NOT NULL,
  `tb_vote_explain` mediumtext NOT NULL,
  PRIMARY KEY  (`tb_vote_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ;

--
-- Dumping data for table `tb_vote_odd`
--

INSERT INTO `tb_vote_odd` VALUES (1, '優秀員工', '李一', '501', '單選', '', '');
INSERT INTO `tb_vote_odd` VALUES (2, '優秀員工', '張楊', '300', '單選', '', '');
INSERT INTO `tb_vote_odd` VALUES (3, '優秀員工', '王幻', '550', '單選', '', '');
INSERT INTO `tb_vote_odd` VALUES (4, '優秀員工', '程一', '751', '單選', '', '');
INSERT INTO `tb_vote_odd` VALUES (5, '優秀員工', '霍伊', '950', '單選', '', '');
INSERT INTO `tb_vote_odd` VALUES (6, '優秀員工', '陸一', '600', '單選', '', '');
INSERT INTO `tb_vote_odd` VALUES (7, '優秀員工', '喬伊', '851', '單選', '', '');

-- --------------------------------------------------------

--
-- Table structure for table `tb_vote_odd_ip`
--

CREATE TABLE `tb_vote_odd_ip` (
  `tb_vote_ip_id` int(10) NOT NULL auto_increment,
  `tb_vote_id` varchar(10) NOT NULL,
  `tb_vote_subject` varchar(80) NOT NULL,
  `tb_vote_content` text NOT NULL,
  `tb_vote_date` datetime NOT NULL,
  `tb_vote_ip` varchar(50) NOT NULL,
  PRIMARY KEY  (`tb_vote_ip_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;

--
-- Dumping data for table `tb_vote_odd_ip`
--

INSERT INTO `tb_vote_odd_ip` VALUES (1, '2', '優秀員工', '張楊', '2008-05-30 01:50:18', '127.0.0.1');
INSERT INTO `tb_vote_odd_ip` VALUES (2, '5', '優秀員工', '霍伊', '2008-06-23 03:43:07', '127.0.0.1');
INSERT INTO `tb_vote_odd_ip` VALUES (6, '4', '優秀員工', '程一', '2008-08-08 03:12:43', '192.168.1.59');
INSERT INTO `tb_vote_odd_ip` VALUES (9, '7', '優秀員工', '喬伊', '2009-08-03 02:15:03', '10.9.1.65');

-- --------------------------------------------------------

--
-- Table structure for table `tb_vote_record`
--

CREATE TABLE `tb_vote_record` (
  `tb_record_id` int(5) NOT NULL auto_increment,
  `tb_vote_id` int(5) NOT NULL default '0',
  `tb_record_name` varchar(50) NOT NULL,
  `tb_record_num` int(5) NOT NULL default '0',
  `tb_record_color` int(1) NOT NULL default '0',
  PRIMARY KEY  (`tb_record_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=75 ;

--
-- Dumping data for table `tb_vote_record`
--

INSERT INTO `tb_vote_record` VALUES (31, 15, '歐陽一', 3, 1);
INSERT INTO `tb_vote_record` VALUES (32, 15, '南宮一', 4, 2);
INSERT INTO `tb_vote_record` VALUES (33, 16, '羽毛球', 0, 3);
INSERT INTO `tb_vote_record` VALUES (34, 16, '射擊', 8, 5);
INSERT INTO `tb_vote_record` VALUES (28, 14, '程一', 4, 1);
INSERT INTO `tb_vote_record` VALUES (29, 14, '張一', 6, 4);
INSERT INTO `tb_vote_record` VALUES (30, 14, '歐陽一', 9, 2);
INSERT INTO `tb_vote_record` VALUES (35, 17, 'C7', 0, 1);
INSERT INTO `tb_vote_record` VALUES (36, 17, '張三', 1, 4);
INSERT INTO `tb_vote_record` VALUES (37, 17, '歐陽', 0, 2);
INSERT INTO `tb_vote_record` VALUES (38, 18, 'fgegr', 1, 2);
INSERT INTO `tb_vote_record` VALUES (39, 18, 'gre', 0, 2);
INSERT INTO `tb_vote_record` VALUES (40, 18, 'gre', 1, 3);
INSERT INTO `tb_vote_record` VALUES (41, 18, 'gr', 0, 4);
INSERT INTO `tb_vote_record` VALUES (42, 18, 'grgeg', 0, 5);
INSERT INTO `tb_vote_record` VALUES (43, 19, 'qeg', 0, 1);
INSERT INTO `tb_vote_record` VALUES (44, 19, 'grqg', 1, 1);
INSERT INTO `tb_vote_record` VALUES (45, 19, 'qgrqe', 0, 1);
INSERT INTO `tb_vote_record` VALUES (46, 19, 'gqgr', 0, 1);
INSERT INTO `tb_vote_record` VALUES (47, 19, 'qqegrqg', 0, 1);
INSERT INTO `tb_vote_record` VALUES (48, 19, 'eqgq', 0, 1);
INSERT INTO `tb_vote_record` VALUES (49, 19, 'qegqegr', 0, 1);
INSERT INTO `tb_vote_record` VALUES (50, 20, '65ki85ki8', 0, 2);
INSERT INTO `tb_vote_record` VALUES (51, 20, 'kr67urk8i', 0, 3);
INSERT INTO `tb_vote_record` VALUES (52, 21, 'e', 0, 1);
INSERT INTO `tb_vote_record` VALUES (53, 21, 'egrwa', 2, 1);
INSERT INTO `tb_vote_record` VALUES (54, 21, 'htwh', 0, 1);
INSERT INTO `tb_vote_record` VALUES (55, 21, 'gq43hg35', 0, 1);
INSERT INTO `tb_vote_record` VALUES (56, 21, 'hq4h5', 0, 1);
INSERT INTO `tb_vote_record` VALUES (57, 22, 'wrhw', 0, 1);
INSERT INTO `tb_vote_record` VALUES (58, 22, 'wrhtw', 0, 1);
INSERT INTO `tb_vote_record` VALUES (59, 22, 'werhwh', 0, 1);
INSERT INTO `tb_vote_record` VALUES (60, 22, 'whwh', 0, 1);
INSERT INTO `tb_vote_record` VALUES (61, 22, 'w54hh54h52w', 0, 1);
INSERT INTO `tb_vote_record` VALUES (62, 23, 'het5', 0, 1);
INSERT INTO `tb_vote_record` VALUES (63, 23, 'h', 0, 1);
INSERT INTO `tb_vote_record` VALUES (64, 23, '', 0, 1);
INSERT INTO `tb_vote_record` VALUES (65, 23, '', 0, 1);
INSERT INTO `tb_vote_record` VALUES (66, 24, '馬先生', 0, 1);
INSERT INTO `tb_vote_record` VALUES (67, 24, '蔡小姐', 0, 1);
INSERT INTO `tb_vote_record` VALUES (68, 24, '不想投', 0, 1);
INSERT INTO `tb_vote_record` VALUES (69, 25, '花不完的錢', 0, 1);
INSERT INTO `tb_vote_record` VALUES (70, 25, '法拉利', 0, 1);
INSERT INTO `tb_vote_record` VALUES (71, 25, '黃金', 0, 1);
INSERT INTO `tb_vote_record` VALUES (72, 25, '瑪瑙', 0, 1);
INSERT INTO `tb_vote_record` VALUES (73, 25, '鑽石', 0, 1);
INSERT INTO `tb_vote_record` VALUES (74, 25, '名牌包', 0, 1);

-- --------------------------------------------------------

--
-- Table structure for table `tb_vote_subject`
--

CREATE TABLE `tb_vote_subject` (
  `tb_vote_subject_id` int(10) NOT NULL auto_increment,
  `tb_vote_subject_name` varchar(80) NOT NULL,
  `tb_vote_subject_text` text NOT NULL,
  PRIMARY KEY  (`tb_vote_subject_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;

--
-- Dumping data for table `tb_vote_subject`
--

INSERT INTO `tb_vote_subject` VALUES (1, '優秀員工', '評選公司內部的優秀員工。');
INSERT INTO `tb_vote_subject` VALUES (2, '優秀負責人', '評選公司內部優秀負責人');
INSERT INTO `tb_vote_subject` VALUES (9, '我最喜歡的比賽項目', '評選我最喜歡的比賽項目');
INSERT INTO `tb_vote_subject` VALUES (8, '我最喜愛的運動員', '評選我最喜愛的運行員');
作者: may    時間: 2011-7-9 21:43

index.php

<?php
    include("conn/conn.php");  // 匯入資料庫設定檔
?>
<html>
<head>
<title>投票選項</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style></head>
<body>
<table width="1003" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3"><img src="images/bg2_06 (3).gif" width="1003" height="160"></td>
  </tr>
  <tr>
    <td width="101" align="right" background="images/b_02.gif">&nbsp;</td>
    <td width="812" valign="top"><table width="812" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="626" height="97"><img src="images/bg2_06 (5).gif" width="626" height="97"></td>
        <td rowspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><img src="images/bg2_06 (6).gif" width="186" height="244"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td align="center" valign="middle">
         
         
        <p>
<a href=vote.php>新增記錄</a>
<p>
<?php
    $sql = "SELECT * FROM tb_vote";
    $result = mysql_query($sql,$conn);
    // 執行 sql 語法  執行結果存到 result 變數(字串陣列)
    $row = mysql_fetch_array($result);
    // 提取 result 陣列
     
    if($row == 0){
    // 如果提取不到投票議題 代表目前沒有投票活動
        echo "目前沒有投票議題!!";
    }else{
?>
<table width="626" border='1' cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" background="images/bg3.gif" bgcolor="#FFFFFF">
<tr>
<td width='163' height="24" align="center">項</td>
<td width='195' align="center">
投票主旨名稱</td>
<td width='260' align="center">操作</td>
</tr>
<?php

    $sql = "SELECT * FROM tb_vote";
    $result = mysql_query($sql,$conn);
    $i = 0;  // 計數
    while($rs = mysql_fetch_array($result)){
        $i++;
?>
<tr>
<td height="24" align="center">
第<?php echo $i;?>條</td>
<td>&nbsp;&nbsp;
<a href="look_vote.php?id=<?php echo $rs['tb_vote_id']  // 顯示議題編號?>"><?php echo $rs['tb_vote_name']  // 議題主旨?></a>
</td>
<td align="center">
<a href="delete_vote.php?id=<?php echo $rs['tb_vote_id']  // 議題編號?>">刪除</a></td>
</tr>
<?php }?>
  </table>
<?php } ?>        </td>
      </tr>
      <tr>
        <td height="59"><img src="images/bg2_06 (1).gif" width="626" height="59"></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
    <td width="90" background="images/bg2_06.gif">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><img src="images/bg2_06 (2).gif" width="1003" height="90"></td>
  </tr>
</table>

</body>
</html>
作者: may    時間: 2011-7-9 21:44

vote.php

<html>
<head>
<title>投票程式</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style></head>
<body>
<script language=javascript>
function check_vote(form)
{
    if (form.v_name.value == "")
    {
        alert("請輸入投票項名稱!");
        theForm.v_name.focus();
        return (false);
    }
}
</script>
<center>
<table width="1003" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3"><img src="images/bg2_06 (3).gif" width="1003" height="160"></td>
  </tr>
  <tr>
    <td width="101" align="right"><img src="images/bg2_06 (4).gif" width="90" height="390"></td>
    <td width="812" valign="top"><table width="812" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="626" height="97"><img src="images/bg2_06 (5).gif" width="626" height="97"></td>
        <td rowspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><img src="images/bg2_06 (6).gif" width="186" height="244"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td align="center" valign="top">
<?php include_once("conn/conn.php");
if((!$_POST[v_name]) &&(!$_POST[r][1])){   // 如果沒有填寫 v_name (投票主旨內容) 、 投票議題的選項
// 第一個步驟 : 填寫主旨、選擇投票類型、選項的數目
?>
<table width="587" border=0 cellpadding="0" cellspacing="0">
<form method="post" action="vote.php" onSubmit="return check_vote(this)">
<tr>
<td width="164" background="images/bg_20.gif"><div align="right">新增投票主旨內容:</div></td>
<td width="462" height="29" background="images/bg_201.gif"><input type=text name=v_name></td>
</tr>
<tr>
<td background="images/bg_20.gif"><div align="right">選擇投票類型:</div></td>
<td height="29" background="images/bg_201.gif">
<input type=radio name=v_type value=0 checked>單選
<input type=radio name=v_type value=1>復選</td>
</tr>
<tr>
<td background="images/bg_20.gif"><div align="right">設置投票項的項數:</div></td>
<td height="29" background="images/bg_201.gif">
<select name=v_m size=1>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
<option value=7>7</option>
<option value=8>8</option>
<option value=9>9</option>
<option value=10>10</option>
</select>
</tr>
<tr>
<td height="29" colspan="2">
<center><input type=submit value="下一步">
</center></td>
</tr>
</form>
</table>
<?php  
    }else if(!$_POST[r][1]){  // 判斷是否已經填寫議題選項
    // 第二個步驟 : 填寫選項
?>
<script language=javascript>
function check_vote(form)
{
    if (form.v_name.value == "")
    {
        alert("請輸入投票項名稱!");
        theForm.v_name.focus();
        return (false);
    }
}
</script>
&nbsp;<table width="587" border=0 cellpadding="0" cellspacing="0">
    <form method="post" action="vote.php" onSubmit="return check_vote(this)">
    <tr>
        <td height="25" colspan=4><center><?php echo $_POST[v_name];?>
        </center></td></tr>
            <input type=hidden name=v_name value="<?php echo $_POST[v_name];?>">
            <input type=hidden name=v_type value="<?php echo $_POST[v_type];?>">
            <input type=hidden name=v_m value="<?php echo $_POST[v_m];?>">
<?php
    for($i=1;$i<($v_m+1);$i++){   // 使用回圈產生選項的文字輸入欄位
?>
    <tr>
        <td width="152" height="29" align="right" background="images/bg_20.gif">選擇項<?php echo $i;?>內容:</td>
        <td width="281" background="images/bg_201.gif"><input type=text name=r[]></td>
        <td width="52" align="right" background="images/bg_20.gif">顏色:</td>
        <td width="102" background="images/bg_201.gif">
            <select size=1 name=c[]>
                <option value=1>紅</option>
                <option value=2>藍</option>
                <option value=3>綠</option>
                <option value=4>黃</option>
                <option value=5>紫</option>
            </select>        </td>
    </tr>
<?php } ?>
    <tr>
        <td height="29" colspan="4"><center>
            <input type=button value="上一步" onclick=history.go(-1)>
            <input type=submit value="下一步"></center>
        </td>
    </tr>
</form>
</table>
<?php
}else{   // 寫入資料庫
    $v_name=$_POST[v_name];        //獲取投票主旨的內容
    $v_type=$_POST[v_type];        //獲取投票類型
    $v_m=$_POST[v_m];            //獲取投票選項的項數
    for($i=0;$i<$v_m;$i++){
        $r[]=$_POST[r][$i];
        $c[]=$_POST[c][$i];
    }
     
     
     
    $sql="insert into tb_vote(tb_vote_name,tb_vote_type,tb_vote_num) values('$v_name','$v_type','$v_m')";
    // 寫入投票議題的 主旨、類型、選項的數量
     
    mysql_query($sql,$conn);
     
    $sqls="select max(tb_vote_id) from tb_vote";
    // 找出投票議題 id 的最大值
     
     
     
    $result=mysql_query($sqls,$conn);
    $row=mysql_fetch_array($result);  // 議題 id 的最大值
    for($i=0;$i<$v_m;$i++){
        $temp=$r[$i];       //獲取投票選項內容
        $temp2=$c[$i];        //獲取投票選項的顏色
        $sqles="insert into tb_vote_record(tb_vote_id,tb_record_name,tb_record_color) values('$row[0]','$temp','$temp2')";
        mysql_query($sqles,$conn);
    }
echo "<meta http-equiv=\"refresh\" content=\"2; url=index.php\">";
echo "投票選項創建成功!兩秒後返回";
}
?>




</td>
      </tr>
      <tr>
        <td height="59"><img src="images/bg2_06 (1).gif" width="626" height="59"></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
    <td width="90"><img src="images/bg2_06.gif" width="90" height="390"></td>
  </tr>
  <tr>
    <td colspan="3"><img src="images/bg2_06 (2).gif" width="1003" height="90"></td>
  </tr>
</table>
</center>
</body>
</html>
作者: may    時間: 2011-7-9 21:46

look_vote.php

<?php
    include("conn/conn.php");
    if(!$_GET['id']){
    // 防止使用者自行進入該頁面,沒有傳入 id 的值
        echo "Sorry! 您走錯路了~!<a href='index2.php'>返回首頁</a>";
        exit();  // 停止程式
    }else{
?>
<html>
<head>
<title>投票程式——顯示投票項</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style></head>
<body>
<table width="1003" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3"><img src="images/bg2_06 (3).gif" width="1003" height="160"></td>
  </tr>
  <tr>
    <td width="101" align="right" background="images/b_02.gif">&nbsp;</td>
    <td width="812" valign="top"><table width="812" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="626" height="97"><img src="images/bg2_06 (5).gif" width="626" height="97"></td>
        <td rowspan="2"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td><img src="images/bg2_06 (6).gif" width="186" height="244"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td align="center" valign="middle">
         
    <center>
<?php

    $sql = "SELECT * FROM tb_vote WHERE tb_vote_id = {$_GET['id']}";
    $result = mysql_query($sql,$conn);
    $row = mysql_fetch_array($result);
    $s = $row['tb_vote_num'];   // 儲存選擇項目有幾個
    echo "<h1>".$row['tb_vote_name']."</h1>";  // 顯示議題主旨
?>

<table width="626" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" background="images/bg3.gif" bgcolor="#FFFFFF">
<form action=look_vote_ok.php method=post>
<input type=hidden name=id value="<?php echo $row['tb_vote_id']?>">
<input type=hidden name=v_type value="<?php echo $row['tb_vote_type']?>">
<tr>
<td width="163" height="25" align="center">&nbsp;</td>
<td width="195" align="center">選項</td>
<td width="260" align="center">投票結果</td>
</tr>
<?php
     
    $sql = "select * from tb_vote_record where tb_vote_id='$_GET[id]'";
    $result = mysql_query($sql,$conn);
    while($rows=mysql_fetch_array($result)){
?>
<tr>
<td height="25" align="center">
<?php
    // 判斷選單的形式, 0 : 單選 1 : 複選
    if($row['tb_vote_type'] == 0){ // 單選
        echo "<input type='radio' name='r' value = {$rows['tb_record_id']}>";
    }else{  // 複選
        echo "<input type='checkbox' name='r[]'  value = {$rows['tb_record_id']}>";
    }


?></td>
<td>&nbsp;<?php echo $rows[tb_record_name];?></td>
<td>&nbsp;
<?php

    if($rows[tb_record_num] == 0){
        $width = 0;
    }else{
        $width = $rows[tb_record_num] / 3;
    }
     
    echo "<img src=$rows[tb_record_color].bmp width = ".($width*20)." height=10> $rows[tb_record_num]";

?>
</td>
</tr>
<?php } ?>

<tr><td height="25" colspan=3><center>
  <input type=submit value="確認提交"></center></td></tr>
</form>
</table>
<?php } ?>
     



</td>
      </tr>
      <tr>
        <td height="59"><img src="images/bg2_06 (1).gif" width="626" height="59"></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
    <td width="90" background="images/bg2_06.gif">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><img src="images/bg2_06 (2).gif" width="1003" height="90"></td>
  </tr>
</table>




</body>
</html>
作者: may    時間: 2011-7-9 21:49

look_vote_ok.php

<?php ob_start();

    include("conn/conn.php");
     
    $id = $_POST['id'];  // 取得投票議題的 id
    $v_type = $_POST['v_type'];   // 取得投票的類型 (單 複選)
    $r = $_POST['r'];   // 取得資料
     
    if($v_type == 0){  // 單選
        // 更新資料庫的票數
        $sql = "UPDATE tb_vote_record SET tb_record_num = tb_record_num + 1 WHERE tb_record_id = $r";
        echo $sql;
        mysql_query($sql, $conn);
     
     
    }else{   // 複選
     
        for($i = 0; $i < count($r); $i++ ){   // 陣列取值
            $temp = $r[$i];   // 取得陣列的值 存入 temp 變數
            $sql = "UPDATE tb_vote_record SET tb_record_num = tb_record_num + 1 WHERE tb_record_id = $temp";
            mysql_query($sql, $conn);
        }
     
    }
    //echo "<meta http-equiv=refresh content=2; url=look_vote.php?id=$id>";  // 轉回前頁
    header("refresh:3;url=look_vote.php?id=$id");  // 轉頁
    echo "投票完成!";
     
     
?>




歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2