手机选择问卷调查分析——PHP与C++进行数据处理

本系统项目源代码:https://github.com/ahongl/StudentManage

1.设计问卷调查表内容:
必填:身份(自己设计分类,例如:学生/体力劳动者/脑力劳动者)
年龄
性别
选填:自行设计单项选择题、填空题
例如:可接受的价格范围(自己设计,可以上限/下限,或某个值+上下浮动)
屏幕大小/整机大小
重量
颜色(也可以选择忽略,即不介意)
待机时间
拍照质量
音响效果
对以上各项指标重要程度的排序
……
2.有50人填写了问卷,某些问题必答、某些问题允许不答
3.自行设计数据输入方法(例如读.txt或.xls文件)

1、利用云服务器基于PHP语言设计网页版调查报告和MySQL数据库;
2、邀请好友进行问卷的填写,收集数据,数据实时写入数据库中;
3、运用C++语言连接MySQL数据库,读取数据;
4、将数据读入对象数组中,通过冒泡排序对数据进行排序,以便于对数据进行分类和排序。

为方便测试,把主要功能模块做成单独的函数,在运行主函数时按测试目的调用功能模块。这些单独的函数有:连接MySQL数据:void mysqlconnet();读取MySQL数据库并存入对象数组中:void read();冒泡排序算法,用于将结果进行分类:void sort(yb ybx, int n, int k);寻找选项中概率最大的项:int seeknum(int a);二维数组初始化:void initResult(int a[9][8]);统计全部结果的数据量:void count(yb ybx, int k);统计男生结果的数据量:void count2(yb *ybx, int k);统计女生结果的数据量:void count3(yb *ybx, int k);计算每个选项的比例:void rate(int a[9][8], double rate[9][8]);利用冒泡排序算法原理设计的概率从大到小排序:int sort2(double* a);利用冒泡排序算法原理设计的概率从小到大排序:int* sort3(double* a);打印指定的选项内容:void dprint(int c,int bl);计算选项的数据量和比例:void count4(yb* ybx,int k)。

源代码如下
mysqlconnect.h
数据库连接类

#pragma once
#include "mysql.h"
#pragma comment(lib,"wsock32.lib")
#pragma comment(lib,"libmysql.lib")
MYSQL mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int k = 0;
void mysqlconnet()//连接MySQL数据库
{
    mysql_init(&mysql);
    mysql_real_connect(&mysql, "localhost", "root", "", "my_db", 3306, NULL, 0);
    /*char *sql1 = "select count(*) from persons";
    mysql_query(&mysql, sql1);
    result=mysql_store_result(&mysql);
    row = mysql_fetch_row(result);
    int sum=atoi(row[0]);*/
    char *sql = "select * from persons";//unicode下用Cstring会很麻烦,直接用char
    mysql_query(&mysql, sql);
    result = mysql_store_result(&mysql);
}
void read()//读取MySQL数据库
{
    while ((row = mysql_fetch_row(result)) != NULL)
    {
        for (int i = 0; i < 9; i++)
        {
            yb1[k].a[i] = row[i];
        }
        k++;
    }
    for (int j = 0; j < k; j++)
    {
        for (int i = 0; i < 9; i++)
        {
            if (i != 4)
                yb1[j].b[i] = atoi(yb1[j].a[i]);
            else if (i == 4)
            {
                char f = yb1[j].a[4][2];
                yb1[j].l = f - '0';
                yb1[j].b[4] = yb1[j].l;
                int q = 0;
                for (int i = 4; i < strlen(yb1[j].a[4]); i++)
                {
                    if (yb1[j].a[4][i] == '"')
                    {
                        yb1[j].c[q] = yb1[j].a[4][i + 1];
                        i = i + 3;
                        q++;
                    }
                    if (q >= yb1[j].l)
                        break;
                }
                /*i = str.find("*");
                str1 = str.substr(0, i);
                str2 = str.substr(i + 1);*/
            }
        }
    }
}

样本类

#pragma once
#include<iostream>
#include<cstring>
using namespace std;

class yb//样本类
{
public:
    yb();
    ~yb();
    char* a[9];
    int b[9];
    char c[6];
    int l;
}yb1[110];

yb::yb()
{
    for (int i = 0; i < 9; i++)
    {
        a[i] = "";
    }
}
yb::~yb()
{
}

样本实现类

#include"yb.h"
#include <string>
int result1[9][8];
int result2[9][8];
int result3[9][8];
double rate1[9][8], rate2[9][8], rate3[9][8];
int result4[5];
void sort(yb *ybx, int n, int k)
{
    for (int i = 0; i <k; i++)
    {
        for (int j = i; j < k; j++)
        {
            if (ybx[i].b[n] > ybx[j].b[n])
            {
                yb temp = ybx[i];
                ybx[i] = ybx[j];
                ybx[j] = temp;
            }
        }
    }
}
int seeknum(int* a)
{
    int big=0;
    int k = 0;
    for (int i = 0; i < 6; i++)
    {
        if (a[i] > big)
        {
            k = i;
            big = a[i];
        }
    }
    return k;
}
void initResult(int a[9][8])
{
    for (int i = 0; i < 9; i++)
    {
        for (int j = 0; j < 8; j++)
        {
            a[i][j] = 0;
        }
    }
}
void count(yb *ybx, int k)
{
    initResult(result1);
    for (int j = 0; j < 9; j++)
    {
        for (int i = 0; i < k; i++)
        {
            result1[j][(ybx[i].b[j]) - 1]++;
        }
    }
}
void count2(yb *ybx, int k)
{
    initResult(result2);
    for (int j = 0; j < 9; j++)
    {
        for (int i = 0; i < result1[0][0]; i++)
        {
            result2[j][(ybx[i].b[j]) - 1]++;
        }
    }
}
void count3(yb *ybx, int k)
{
    initResult(result3);
    for (int j = 0; j < 9; j++)
    {
        for (int i = k - result1[0][1]; i <k; i++)
        {
            result3[j][(ybx[i].b[j]) - 1]++;
        }
    }
}
void rate(int a[9][8], double rate[9][8])
{
    int sum = 0;
    for (int i = 0; i < 9; i++)
    {
        sum = 0;
        for (int z = 0; z < 8; z++)
        {
            sum = sum + a[i][z];
        }
        for (int j = 0; j < 8; j++)
        {
            rate[i][j] = (double)a[i][j] / sum;
        }
    }
}
int* sort2(double* a)
{
    double b[8];
    for (int i = 0; i < 8; i++)
    {
        b[i] = a[i];
    }
    int *s;
    s = new int[8];
    for (int i = 0; i < 8; i++)
    {
        s[i] = i;
    }
    for (int i = 0; i <8; i++)
    {
        for (int j = i; j < 8; j++)
        {
            if (b[i] < b[j])
            {
                int p = b[i];
                b[i] = b[j];
                b[j] = p;
                int temp = s[i];
                s[i] = s[j];
                s[j] = temp;
            }
        }
    }
    return s;
}
int* sort3(double* a)
{
    double b[8];
    for (int i = 0; i < 8; i++)
    {
        b[i] = a[i];
    }
    int *s;
    s = new int[8];
    for (int i = 0; i < 8; i++)
    {
        s[i] = i;
    }
    for (int i = 0; i <8; i++)
    {
        for (int j = i; j < 8; j++)
        {
            if (b[i] > b[j])
            {
                int p = b[i];
                b[i] = b[j];
                b[j] = p;
                int temp = s[i];
                s[i] = s[j];
                s[j] = temp;
            }
        }
    }
    return s;
}
void dprint(int c,int bl)
{
    string a[9][8] = { { "男","女" },{ "18岁以下","18~25","26~30","31~40","41~50","51~60","60以上" },{ "苹果","小米","vivo","oppo","华为","三星","魅族","其他" },{ "苹果","小米","vivo","oppo","华为","三星","魅族","其他" },{ "外形好看、美观","手机内存大,不会卡顿","属于拍照手机,像素高,适合拍照","质量好,功能强大","电池耐用度","网速快慢" },{ "玫瑰金","香槟金","粉色","银色","黑色","白色","其他" },{ "大屏手机","偏薄偏轻","高端大气","适中无所谓","其他" },{ "玩游戏","听音乐","看视频电影","聊天、浏览朋友圈","逛微博、浏览新闻","其他" },{ "1小时以内","2~4小时","4~6小时","6~8小时","8小时以上" } };
    cout<< a[c][bl];
}
void count4(yb* ybx,int k)
{
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < 6; j++)
        {
            if (ybx[i].c[j] == '1')
            {
                result4[0]++;
            }
            else if (ybx[i].c[j] == '2')
            {
                result4[1]++;
            }
            else if(ybx[i].c[j] == '3')
            {
                result4[2]++;
            }
            else if (ybx[i].c[j] == '4')
            {
                result4[3]++;
            }
            else if (ybx[i].c[j] == '5')
            {
                result4[4]++;
            }
            else if (ybx[i].c[j] == '6')
            {
                result4[5]++;
            }
        }
    }
}

网站前端html页面

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.button
{
width:100px;
display: block; 
    font-size: 12px; 
    text-decoration: none!important; 
    font-family: Helvetica, Arial, sans serif;
    padding: 8px 12px; 
    border-radius: 3px; 
    -moz-border-radius: 3px; 
    box-shadow: inset 0px 0px 2px #fff;
    -o-box-shadow: inset 0px 0px 2px #fff;
    -webkit-box-shadow: inset 0px 0px 2px #fff;
    -moz-box-shadow: inset 0px 0px 2px #fff;
    color: #41788c;
    border: 1px solid #6fb1c7;
    background-image: -moz-linear-gradient(#aae5f7, #73d0f1);
    background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#73d0f1), to(#aae5f7));
    background-image: -webkit-linear-gradient(#aae5f7, #73d0f1);
    background-image: -o-linear-gradient(#aae5f7, #73d0f1);
    text-shadow: 1px 1px 1px #bfeafb;
    background-color: #73d0f1;
}
.button:hover {
    border: 1px solid #4690ad;
    background-image: -moz-linear-gradient(#73d0f1, #aae5f7);
    background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#aae5f7), to(#73d0f1));
    background-image: -webkit-linear-gradient(#73d0f1, #aae5f7);
    background-image: -o-linear-gradient(#73d0f1, #aae5f7);
    background-color: #aae5f7;
}
body { margin:auto; font-size:14px; background-repeat: repeat-x;  background-color:#F6E7D0;}
table { border:0; margin:auto;}
b { color:#DA4A4A;}
a:link { color:#fff; text-decoration: none; }
a:visited { color:#fff; text-decoration: none;}
a:active { color:#fff; text-decoration: none;}
a:hover { color:#ffff00; text-decoration: underline;}
#banner{ font-size:40px; color:#fff; font-family:"黑体"; padding-left:150px; background:url(../images/logo.jpg); width:960px; height:210px;}
#info { font-size:14px; background-color:#F6E7D0; padding:10px 20px; line-height:25px;}
#info2 { background-color:#DA4A4A; height:3px;}
#BigTitle { padding:10px; font-size:15px; font-weight:bold; line-height:25px;}
#Notice { background:url(../images/Notice.jpg); width:350px; height:337px;}
#Noticeb{ margin:160px 50px 60px 105px; color:#333333; font-size:14px; font-weight:bold;}
#Notice a { color:#000000; text-decoration:none;}
#Notice a:hover { color:#0066FF; text-decoration: underline;}
#nopaper{ color:#ff0000; font-size:14px; font-weight:bold; line-height:30px;}
</style>
<link href="images/index.css" rel="stylesheet" type="text/css">
<script src="check.js"></script>
<script>
 if (window.Event) 
    document.captureEvents(Event.MOUSEUP); 
    function nocontextmenu(){ 
     event.cancelBubble = true 
     event.returnValue = false; 
     return false; 
    } 
    function norightclick(e){ 
     if (window.Event){ 
      if (e.which == 2 || e.which == 3) 
      return false; 
     } 
     else 
      if (event.button == 2 || event.button == 3){ 
       event.cancelBubble = true 
       event.returnValue = false; 
       return false; 
      } 
    } 
    document.oncontextmenu = nocontextmenu; // for IE5+ 
    document.onmousedown = norightclick; // for all others 
</script>
</head>
<body onmousedown="rclick()" oncontextmenu= "nocontextmenu()">
<table width="960px" align="center" bgcolor="#FAFAFA">
<h1 align="center">关于手机的调查问卷</h1>
<form id="form1" name="fm" method="post" action="submit.php" onsubmit="return checkForm(this)"> 
 <tr>
  <td id="info2" colspan="6"></td>
 </tr>
 <tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>1、您的性别[单选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="radio" name="Option1" value=1 title="请选择“第1题”~!" /><BR>
      <input type="radio" name="Option1" value=2 title="请选择“第1题”~!" /><BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
 <tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>2、您的年龄段是[单选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="radio" name="Option2" value=1 title="请选择“第2题”~!" /> 18岁以下 <BR>
      <input type="radio" name="Option2" value=2 title="请选择“第2题”~!" /> 18~25 <BR>
      <input type="radio" name="Option2" value=3 title="请选择“第2题”~!" /> 26~30 <BR>
      <input type="radio" name="Option2" value=4 title="请选择“第2题”~!" /> 31~40 <BR>
      <input type="radio" name="Option2" value=5 title="请选择“第2题”~!" /> 41~50 <BR>
      <input type="radio" name="Option2" value=6 title="请选择“第2题”~!" /> 51~60 <BR>
      <input type="radio" name="Option2" value=7 title="请选择“第2题”~!" /> 60以上 <BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
 <tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>3、您的手机是什么品牌呢?[单选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="radio" name="Option3" value=1 title="请选择“第3题”~!" /> 苹果 <BR>
      <input type="radio" name="Option3" value=2 title="请选择“第3题”~!" /> 小米 <BR>
      <input type="radio" name="Option3" value=3 title="请选择“第3题”~!" /> vivo <BR>
      <input type="radio" name="Option3" value=4 title="请选择“第3题”~!" /> oppo <BR>
      <input type="radio" name="Option3" value=5 title="请选择“第3题”~!" /> 华为 <BR>
      <input type="radio" name="Option3" value=6 title="请选择“第3题”~!" /> 三星 <BR>
      <input type="radio" name="Option3" value=7 title="请选择“第3题”~!" /> 魅族 <BR>
      <input type="radio" name="Option3" value=8 title="请选择“第3题”~!" /> 其他 <BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
  <tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>4、您最喜欢的手机品牌是什么呢?[单选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="radio" name="Option4" value=1 title="请选择“第4题”~!" /> 苹果 <BR>
      <input type="radio" name="Option4" value=2 title="请选择“第4题”~!" /> 小米 <BR>
      <input type="radio" name="Option4" value=3 title="请选择“第4题”~!" /> vivo <BR>
      <input type="radio" name="Option4" value=4 title="请选择“第4题”~!" /> oppo <BR>
      <input type="radio" name="Option4" value=5 title="请选择“第4题”~!" /> 华为 <BR>
      <input type="radio" name="Option4" value=6 title="请选择“第4题”~!" /> 三星 <BR>
      <input type="radio" name="Option4" value=7 title="请选择“第4题”~!" /> 魅族 <BR>
      <input type="radio" name="Option4" value=8 title="请选择“第4题”~!" /> 其他 <BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
 <tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>5、对于手机,你更看重的是手机的哪些方面?[多选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="checkbox" name="Option5[]" value=1 title="请选择“第5题”~min:1" /> 外形好看、美观 <BR>
      <input type="checkbox" name="Option5[]" value=2 title="请选择“第5题”~min:1" /> 手机内存大,不会卡顿 <BR>
      <input type="checkbox" name="Option5[]" value=3 title="请选择“第5题”~min:1" /> 属于拍照手机,像素高,适合拍照 <BR>
<input type="checkbox" name="Option5[]" value=4 title="请选择“第5题”~min:1" /> 质量好,功能强大 <BR>
<input type="checkbox" name="Option5[]" value=5 title="请选择“第5题”~min:1" /> 电池耐用度 <BR>
     <input type="checkbox" name="Option5[]" value=6 title="请选择“第5题”~min:1" /> 网速快慢 <BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
<tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>6、您最喜欢的手机颜色是什么呢?[单选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="radio" name="Option6" value=1 title="请选择“第6题”~!" /> 玫瑰金 <BR>
      <input type="radio" name="Option6" value=2 title="请选择“第6题”~!" /> 香槟金 <BR>
      <input type="radio" name="Option6" value=3 title="请选择“第6题”~!" /> 粉色 <BR>
      <input type="radio" name="Option6" value=4 title="请选择“第6题”~!" /> 银色 <BR>
      <input type="radio" name="Option6" value=5 title="请选择“第6题”~!" /> 黑色 <BR>
      <input type="radio" name="Option6" value=6 title="请选择“第6题”~!" /> 白色 <BR>
      <input type="radio" name="Option6" value=7 title="请选择“第6题”~!" /> 其他 <BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
 <tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>7、您更喜欢哪种外形的手机呢?[单选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="radio" name="Option7" value=1 title="请选择“第7题”~!" /> 大屏手机 <BR>
      <input type="radio" name="Option7" value=2 title="请选择“第7题”~!" /> 偏薄偏轻 <BR>
      <input type="radio" name="Option7" value=3 title="请选择“第7题”~!" /> 高端大气 <BR>
      <input type="radio" name="Option7" value=4 title="请选择“第7题”~!" /> 适中无所谓 <BR>
      <input type="radio" name="Option7" value=5 title="请选择“第7题”~!" /> 其他 <BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
 <tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>8、对于手机,除了通信之外,你最常使用的功能是什么呢[单选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="radio" name="Option8" value=1 title="请选择“第8题”~!" /> 玩游戏 <BR>
      <input type="radio" name="Option8" value=2 title="请选择“第8题”~!" /> 听音乐 <BR>
      <input type="radio" name="Option8" value=3 title="请选择“第8题”~!" /> 看视频电影 <BR>
      <input type="radio" name="Option8" value=4 title="请选择“第8题”~!" /> 聊天、浏览朋友圈 <BR>
      <input type="radio" name="Option8" value=5 title="请选择“第8题”~!" /> 逛微博、浏览新闻 <BR>
      <input type="radio" name="Option8" value=6 title="请选择“第8题”~!" /> 其他 <BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
 <tr onMouseOver="this.bgColor='#F6E7D0'" onMouseOut="this.bgColor='#FAFAFA'">
  <td colspan="4"><table width="98%" cellpadding="0" cellspacing="5" align="center">
    <tr>
      <td><b>9、你平均每天使用手机的时间是多少呢?[单选题]</b></td>
    </tr>
    <tr>
      <td>
      <input type="radio" name="Option9" value=1 title="请选择“第9题”~!" /> 1小时以内 <BR>
      <input type="radio" name="Option9" value=2 title="请选择“第9题”~!" /> 2-4小时 <BR>
      <input type="radio" name="Option9" value=3 title="请选择“第9题”~!" /> 4-6小时 <BR>
      <input type="radio" name="Option9" value=4 title="请选择“第9题”~!" /> 6-8小时 <BR>  
      <input type="radio" name="Option9" value=5 title="请选择“第9题”~!" /> 8小时以上 <BR>
      </td>
    </tr>
   </table>
  </td>
 </tr>
  <tr>
    <td colspan="5" align="center">
    <input type="submit" name="Submit" class="button" value=" 提 交 "/>
    <input name="rsCount" type="hidden" id="rsCount" value="13" /></td>
  </tr>
</form>
</table>
<table cellSpacing=0 cellPadding=0 align=center background="images/botbj.jpg" width="960px">
  <tr>
    <td height=60 align="center"> Copyright 2008-2017 版权所有</td>
  </tr>
</table>
</body>
</html>

网站后端处理php文件

<?php
$a="abdc";
$delete_last = substr($a,strlen($a)-1,strlen($a));
printf($delete_last);
error_reporting(0);
$staff_serialize = serialize($_POST[Option5]);
$mysqli=new mysqli("mysql.hostinger.com.hk","u963430622_123","123456","u963430622_test");
//$con = mysql_connect("mysql.hostinger.com.hk","u963430622_123","123456");
 if(mysqli_connect_errno())
    {
        cout(mysqli_connect_error(),1);
        return false;
    }
//mysql_select_db("u963430622_test", $con);
$sql="INSERT INTO persons (op1,op2,op3,op4,op5,op6,op7,op8,op9)
VALUES
('$_POST[Option1]','$_POST[Option2]','$_POST[Option3]','$_POST[Option4]','$staff_serialize','$_POST[Option6]','$_POST[Option7]','$_POST[Option8]','$_POST[Option9]')";
if (!mysqli_query($mysqli,$sql))
  { 
    echo "<script language=\"JavaScript\">alert(\"您好,感谢您的作答,请检查所有的答案是否已经填完!谢谢~\");</script>"; 
    echo "<script>location.href='index.html';</script>";  
    die('Error: ' . mysql_error());
  }
  echo "<script language=\"JavaScript\">alert(\"谢谢你~\");</script>"; 
//echo "1 record added";
mysqli_close($mysqli)
?>
<html>
<h1 align="center">您好,感谢您的作答~</h1>
</html>

js文件

  function checkForm(fm)
    {
        for(var i=0;i<fm.length;i++)
        {
            var title=fm[i].title;
            if(title=="")continue;//忽略未定义title的元素
            var p=title.lastIndexOf("~");
            if(p<0)continue;//忽略title中未定义检查格式的元素
            var info=title.substring(0,p);
            var format=title.substring(p+1,title.length);
            var name=fm[i].name;
            if(name=="")continue;//忽略没有名字的元素
            var value=trim(fm[i].value);
            //fm[i].value=value;//自动除去提交项的两端的空格
            if(fm[i].type=="radio")
            {
                if(checkRadio(fm,fm[i]))
                {
                    continue;
                }
                else
                {
                    return false;
                }
            }       
            if(fm[i].type=="checkbox")
            {
                if(checkCheckbox(fm,fm[i]))
                {
                    continue;
                }
                else
                {
                    return false;
                }
            }

        }
        return true;
    }
    function checkRadio(fm,opt)
    {
        var title=opt.title;
        if(title=="")return true;//忽略未定义title的元素
        var p=title.lastIndexOf("~");
        if(p<0)return true;//忽略title中未定义检查格式的元素
        var info=title.substring(0,p);
        var format=title.substring(p+1,title.length);
        var name=opt.name;
        if(name=="")return true;//忽略没有名字的元素
        if(format=="!")
        {
            //必须选择一个选项
            if(typeof(fm.all[name].length)=="undefined")
            {
                //同名radio只有一个
                if(opt.checked)
                {
                    return true;
                }
                else
                {
                    alert(info+"\n必须选择"+name);
                    opt.focus();
                    return false;
                }
            }
            else
            {
                //是一个radio组
                var radios=fm[name];
                for(var j=0;j<radios.length;j++)
                {
                    if(radios[j].checked==true)return true;
                }
                alert(info+"\n必须选择此题");
                opt.focus();
                return false;
            }
        }
        else
        {
            //可以一个选项也不选
            return true;
        }
    }


    function checkCheckbox(fm,opt)
    {
        var title=opt.title;
        if(title=="")return true;//忽略未定义title的元素
        var p=title.lastIndexOf("~");
        if(p<0)return true;//忽略title中未定义检查格式的元素
        var info=title.substring(0,p);
        var format=title.substring(p+1,title.length);
        var name=opt.name;
        if(name=="")return true;//忽略没有名字的元素

        var min=format.match(/min:(\d+)\w*/);
        var max=format.match(/\w*max:(\d+)/);

        if(typeof(fm.all[name].length)=="undefined")
        {
            //只有一个同名checkbox
            if(min!=null)
            {
                if(min[1]==1&&!opt.checked)
                {
                    alert(info+"\n必须选上"+name+"选项");
                    opt.focus();
                    return false;
                }
            }
        }
        else
        {
            //一个checkbox组
            var checkboxes=fm.all[name];
            var check_count=0;
            for(var j=0;j<checkboxes.length;j++)
            {
                if(checkboxes[j].checked)check_count++;
            }
            if(min!=null)
            {
                if(min[1]>check_count)
                {
                    alert(info+"\n至少需要选择"+min[1]+"个选项");
                    opt.focus();
                    return false;
                }
            }
            if(max!=null)
            {
                if(max[1]<check_count)
                {
                    alert(info+"\n至多可以选择"+max[1]+"个选项");
                    opt.focus();
                    return false;
                }
            }
        }
        return true;
    }
/**
 * 除去字符串变量s两端的空格。
 */
    function trim(s)
    {
        s=s.replace(/^ */,"");
        s=s.replace(/ *$/,"");
        return s;
    }
/**
 * 除去字符串表示的数值变量开头的所有的"0"。
 * 比如
 *  trim0("01")将返回"1"
 *  trim0("1")将返回"1"
 *  trim0("10")将返回"10"
 *  trim0("000")将返回"0"
 */
    function trim0(s)
    {
        if(s.length==0)return s;
        s=s.replace(/^0*/,"");
        if(s.length==0)s="0";
        return s;
    }
/**
 * 取得一个form对象所提交时内部提交参数的QueryString
 * 形如:
 * ?accountName=&userName=&email=&area=0&credit_low=&credit_high=&age_low=&age_high=&userLevel=0
 */
    function getQueryString(fm)
    {
        var qStr="";
        for(var i=0;i<fm.length;i++)
        {
            if(!fm[i].disabled)
            {
                var n=fm[i].name;
                if(n==null)continue;
                if(n.length==0)continue;
                if(fm[i].type=="select-multiple")
                {
                    var _vs=fm[i].options;
                    for(var _j=0;_j<_vs.length;_j++)
                    {
                        var _opt=_vs(_j);
                        if(_opt.selected)
                        {
                            var v=_opt.value;
                            qStr=qStr+"&"+n+"="+ec(v);
                        }
                    }
                }
                else
                {
                    var v=fm[i].value;
                    if(fm[i].type=="radio"||fm[i].type=="checkbox")
                    {
                        if(!fm[i].checked)continue;
                    }
                    qStr=qStr+"&"+n+"="+ec(v);
                }
            }
        }
        if(qStr.length>0)qStr="?"+qStr.substr(1);
        return qStr;
    }
    function ec(va)
    {
        return va.replace(/\n/g,"%0D%0A");
    }

(1)PHP调查问卷
这里写图片描述
这里写图片描述
这里写图片描述
(2)数据库数据
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
(3)问卷数据分析
这里写图片描述

本程序设计了PHP网页版调查问卷,并通过创建数据库的方式保存数据,然后通过C++连接数据库的方式读取数据,最终通过函数、算法对数据进行整合与分析。
在编写源程序过程中,考虑了网页调查问卷界面的设计,数据库的设计(主要是多选题数据数组存入数据库的处理。然后就是冒泡算法的改装,对数据进行分类,分组分析和统计。

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值