Manual of PHP

 
 
 

Web map

 
rim   rim
arrowReady frontarrow of Codes PHParrow Polls with PHP

 

He polls with PHP To print E-mail

We are going to see how we can create a simple survey with MySQL that stores the votings of the users in the database together with his direction ip to control that every user votes only one time.

The first step that we will do will be the conditioning of the database, in which we will create a table using the following judgment:

ONE BELIEVE TABLE `encuesta` (
`ip` VARCHAR (16) NOT NULL,
`voto` INT (1) NOT NULL,
UNIQUE (
`ip`
)
); 

Except if we want that the same user could vote time and again in whose case we will do:

ONE BELIEVE TABLE `encuesta` (
`ip` VARCHAR (16) NOT NULL,
`voto` INT (1) NOT NULL
); 


The functioning of the survey is very simple, the program will read the possible options of vote of a called array $opciones, that you will be able to modify to your will, then it will iterate so many times like elements have the array to show the current results of every option.

To be able to show the percentages, the first thing that we do it is a general consultation that returns us the entire number of received votes, of that time, in every option we will do the following operation:

$porcentaje = round ($votos/$total*100,2);

That will return us the percentage of votes rounded to 2 decimal ones using the function round.

Article for courteousness of Eloi of St Martin
www.programacionweb.net

 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

Earn money , Chasse Pologne aux cerfs , Paid to Read Blog , panasonic , speed test , plastics , Replica Handbags