Minimal php poll script


This is really minimal php script with classical options. No database! This is not ajax based script.


minimal php poll - options


Minimal php poll EXAMPLES


What's your favorite character?

Obe-one
Master Yoda
Darth Vader
Darth Sidious
Chewbacca
Luke
Laia

What's your favorite character?

Obe-one [134 votes]
Master Yoda [84 votes]
Darth Vader [77 votes]
Darth Sidious [42 votes]
Chewbacca [43 votes]
Luke [48 votes]
Laia [49 votes]
Total 477

Perhaps you ilke default blue strip animation?

Yes, looks cool!
It's ok, maybe I'll use it in the future
No, I prefer customizing my polls

Perhaps you ilke default blue strip animation?

Yes, looks cool! [92 votes]
It's ok, maybe I'll use it in the future [2 votes]
No, I prefer customizing my polls [39 votes]
Total 133

Do you like to show percetage in stead of absolute votes?

Yes, always!
No, I prefer absolute numbers.

Do you like to show percetage in stead of absolute votes?

Yes, always! 64%
No, I prefer absolute numbers. 35%
Total 128

You can adjust your own poll size, nice?

Yes, it's neat.
Like it.
No, I don't care.

You can adjust your own poll size, nice?

Yes, it's neat. [5 votes]
Like it. [35 votes]
No, I don't care. [1 votes]
Total 41

Install php poll script

STEP 1
Between HEAD tag, place the following code (bootstrap). [ On page you want to display your poll ]
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
STEP 2
BEFORE head tag, on very top, place the following:
CreatePoll(poll_id, poll question, array of possible options)


include_once(dirname(__FILE__) . "/mp.php");
	$mp = new Mp();

	$mp->createPoll(1,
		"What's your favorite character?",
		array(
			"Obe-one",
			"Master Yoda",
			"Darth Vader",
			"Darth Sidious",
			"Chewbacca",
			"Luke",
			"Laia"
		)
	);

To create more polls on same page, just define different poll_id (numeric) , change question and options. EXAMPLE


	$mp->createPoll(2,
		"Poll with poll_id 2, right?",
		array(
			"yes.",
			"absolutely."
		)
	);

STEP 3



/* setColor($poll_id, $foreground-color, $background-color)  */
/* $foreground-color -> color of text.  */
/* $background-color -> color of background.  */
$mp->setColor(1, "#fda107", "#303030");


/* displayPoll function generates poll voting on page where you place this code.
 Poll won't be shown if user already voted. displayPoll param is poll_id [should match with creation poll_id]
 */	
echo $mp->displayPoll(1);

/* Shows poll results on page. * displayResult($poll_id, $count = false, $width = 220, $style = "default") */
/* $poll_id -> creation poll id */
/* $count -> show absolute numbers or percentage Check out EXAMPLES */
/* $width -> size of poll in displayResult */
/* "default" for future development */
echo $mp->displayResult(1, false, 220, "default");



Download script

Simple enough you only need to download one file (mp.php.txt) UPLOAD it to your server and RENAME to mp.php.
That's it, you're ready to go, enjoy your poll script. Hope it serves you well.
If you find mp useful, consider small donation.

FAQ

When I vote, no results are writen, what's wrong?

First check out /data/ folder (is should be created by default, if there is on /data/ directory, create it manually.) Also check permissions of your /data/ directory. Set it to 644.


When I vote, page is refreshed, why?

This is not ajax script, it's php-only. So this is by design.


Can I create multiple votes on same page?

Yes, check out install php poll script section.


Where are poll results stored?

In files, specificly in /data/ directory under $Poll_id check out 1, 2, 3, ... (number you gave specific poll)


Can I change poll design, apart from setColor function?

Yes, but you'll have to hack mp.php file (Mp class) on your own. Check out displayResult function, you should find html code at the end.