Use PHP to make a survey

Source: Internet
Author: User
Please contact me with any Title: http://www.webjx.comweb @ webjx.com reprinted please indicate the source today to tell you how to use PHP to do the investigation example, through this example you can learn how to use PHP and MYSQL to implement programming, this example is not difficult, look forward to what title please contact me: http://www.webjx.com web@webjx.com
Reprinted please indicate the source

Today, I will give you an example of how to use PHP for investigation. through this example, you can learn how to use PHP and MYSQL for programming. This example is not difficult.

Create a MYSQ
Database table. the specific fields and settings in the table are as follows:

# Table structure for table poll_data
#
Create table poll_data (
ID tinyint (4) not null auto_increment,
Option1 tinyint (4) not null default '0 ',
Option2 tinyint (4) not null default '0 ',
Option3 tinyint (4) not null default '0 ',
Votes tinyint (4) not null default '0 ',
Title varchar (25) not null default '',
Question varchar (50) not null default '',
Primary key (ID)
) TYPE = MyISAM;
After the database table is created, we need to begin to write code to solve this title. We usually solve a title and are willing to break it down so that all titles can be solved. Next we will use this method to compile the program code.
The important functions of this survey are:
1. display the title and title of the survey.
2. display the title of each voting item, the percentage of total voting items, and the percentage of voting items.
3. create a program file that promises to vote in the investigation.
Next we will break down the title:
1. display the title and title of the survey.
A. database connection code
B. select the latest record from the database.
2. display the title of each voting item, the percentage of total voting items, and the percentage of voting items.
A. select the number of votes for each project and display the total number of votes in the survey.
B. The number of votes and the total number of votes can be divided to a percentage.
3. create a program file that promises to vote in the investigation.
A. results should be updated after user voting

We apply some variables to help us connect to the database. The code is as follows:
$ Dbhost = 'localhost ';
$ Dbname = 'yourdatabase ';
$ Dbuser = 'yourusername ';
$ Dbpass = 'yourpass ';

Then we start to connect to the database:
$ Link_id = mysql_connect ($ dbhost, $ dbuser, $ dbpass );
Mysql_select_db ($ dbname );
What we are doing now is the specific database content. The Request database can actively add records, and the program extracts the latest records. the ID can be automatically upgraded. the database code is as follows:

$ SQL = 'select' Title ', 'Question', 'id' FROM 'poll _ data' ORDER BY 'id' DESC LIMIT 1 ';
If (! ($ Result = mysql_query ($ SQL) die (mysql_error ());
$ PollData = mysql_fetch_array ($ result)

Next we will select a specific voting project and calculate the specific percentage!

$ SQL = 'select' option1', 'option2', 'option3', 'Votes 'FROM 'poll _ data' WHERE 'id' = ''. $ PollData ['id']. ''Order BY 'id' desc limit 1 ';
If (! ($ Result = mysql_query ($ SQL) die (mysql_error ());
If (! ($ VoteData = mysql_fetch_array ($ result) die (mysql_error ());

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.