Creating a Dynamic Poll with jQuery and PHP

Tutorial Details
  • Difficulty: Intermediate
  • Completion Time: 1 hours

When you combine some neat functionality courtesy of PHP with the cleverness of jQuery you can produce some pretty cool results. In this tutorial we’ll create a poll using PHP and XHTML, then make use of some jQuery Ajax effects to eliminate the need for a page refresh, and to give it a nice little bit of animation.

  1. HTML
  2. PHP
    1. Introduction
    2. poll_default()
    3. poll_submit()
    4. poll_return_results()
    5. poll_ajax()
  3. CSS
  4. Javascript
    1. Introduction
    2. formProcess()
    3. loadResults()
    4. animateResults()

HTML

Let’s get our <head> set up:

<link href="style.css" rel="stylesheet" type="text/css" />
<script src="jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
<script src="poll.js" type="text/javascript" charset="utf-8"></script>
  • style.css will hold the CSS markup.
  • jquery.js is the base jQuery library.
  • jquery.cookie.js is a plugin by Klaus Hartl to add cookie manipulation to jQuery.
  • poll.js will have the Javascript that makes the poll dynamic.

Next, we’ll create a simple poll form:

Poll
<div id="poll-container">
    <h3>Poll</h3>
    <form id='poll' action="poll.php" method="post" accept-charset="utf-8">
        <p>Pick your favorite Javascript framework:</p>
        <p><input type="radio" name="poll" value="opt1" id="opt1" /><label for='opt1'>&nbsp;jQuery</label><br />
        <input type="radio" name="poll" value="opt2" id="opt2" /><label for='opt2'>&nbsp;Ext JS</label><br />
        <input type="radio" name="poll" value="opt3" id="opt3" /><label for='opt3'>&nbsp;Dojo</label><br />
        <input type="radio" name="poll" value="opt4" id="opt4" /><label for='opt4'>&nbsp;Prototype</label><br />
        <input type="radio" name="poll" value="opt5" id="opt5" /><label for='opt5'>&nbsp;YUI</label><br />
        <input type="radio" name="poll" value="opt6" id="opt6" /><label for='opt6'>&nbsp;mootools</label><br /><br />
        <input type="submit" value="Vote &rarr;" /></p>
    </form>
</div>

This form will be processed by the PHP for now, and when we get the Javascript running, by jQuery. The PHP and Javascript are designed to pull the option ID from the value tag. &nbsp; is just a HTML entity encoded space, and &rarr; is an arrow: →.


PHP

Introduction

If Javascript is disabled, the PHP will:

  1. Take GET/POST requests from the form
  2. Set/check a cookie
  3. Make sure the request is from a unique IP
  4. Store the vote in a flat file DB
  5. Return the results included with a HTML file

If Javascript is enabled, the PHP will:

  1. Take GET/POST requests from the Javascript
  2. Make sure the request is from a unique IP
  3. Store the vote in a flat file DB
  4. Return the results as JSON

For the flat file DB we will be using a package written by Luke Plant.

First, we need an array with the names and IDs of the poll options:

<?php
$options[1] = 'jQuery';
$options[2] = 'Ext JS';
$options[3] = 'Dojo';
$options[4] = 'Prototype';
$options[5] = 'YUI';
$options[6] = 'mootools';

The flatfile package uses numbers for the column identifiers, so lets set some constants to convert those to names:

define('OPT_ID', 0);
define('OPT_TITLE', 1);
define('OPT_VOTES', 2);

When the form is submitted, PHP needs to know what file to insert the results into and return, so we set another constant:

define('HTML_FILE', 'index.html');

We need to include flatfile.php and initialize a database object:

require_once('flatfile.php');
$db = new Flatfile();

The flat files are just text files stored in the data directory:

$db->datadir = 'data/';
define('VOTE_DB', 'votes.txt');
define('IP_DB', 'ips.txt');

If we get a request with the poll parameter, it’s the static form, so we process it. If the request has a vote parameter in it, it’s a Ajax request. Otherwise, we just return the HTML_FILE.

if ($_GET['poll'] || $_POST['poll']) {
  poll_submit();
}
else if ($_GET['vote'] || $_POST['vote']) {
  poll_ajax();
}
else {
  poll_default();
}

poll_default()

function poll_default() {
  global $db;

  $ip_result = $db->selectUnique(IP_DB, 0, $_SERVER['REMOTE_ADDR']);

  if (!isset($_COOKIE['vote_id']) && empty($ip_result)) {
    print file_get_contents(HTML_FILE);
  }  
  else {
    poll_return_results($_COOKIE['vote_id']);
  }
}

poll_default() processes requests directly to the script with no valid GET/POST requests.

The global line makes the $db object available in the function’s scope.

The script tracks unique IPs to make sure you can only vote once, so we do a query to check whether it is in the DB:

$ip_result = $db->selectUnique(IP_DB, 0, $_SERVER['REMOTE_ADDR']);

If we don’t have a cookie and the IP query comes up empty, the client hasn’t voted yet, so we can just send the HTML file which contains the form. Otherwise, we just send the results:

if (!isset($_COOKIE['vote_id']) && empty($ip_result)) {
  print file_get_contents(HTML_FILE);
}  
else {
  poll_return_results($_COOKIE['vote_id']);
}

poll_submit()

function poll_submit() {
  global $db;
  global $options;

  $id = $_GET['poll'] || $_POST['poll'];
  $id = str_replace("opt", '', $id);

  $ip_result = $db->selectUnique(IP_DB, 0, $_SERVER['REMOTE_ADDR']);

  if (!isset($_COOKIE['vote_id']) && empty($ip_result)) {
    $row = $db->selectUnique(VOTE_DB, OPT_ID, $id);
    if (!empty($row)) {
      $ip[0] = $_SERVER['REMOTE_ADDR'];
      $db->insert(IP_DB, $ip);

      setcookie("vote_id", $id, time()+31556926);

      $new_votes = $row[OPT_VOTES]+1;
      $db->updateSetWhere(VOTE_DB, array(OPT_VOTES => $new_votes), new SimpleWhereClause(OPT_ID, '=', $id));

      poll_return_results($id);
    }
    else if ($options[$id]) {
      $ip[0] = $_SERVER['REMOTE_ADDR'];
      $db->insert(IP_DB, $ip);

      setcookie("vote_id", $id, time()+31556926);

      $new_row[OPT_ID] = $id;
      $new_row[OPT_TITLE] = $options[$id];
      $new_row[OPT_VOTES] = 1;
      $db->insert(VOTE_DB, $new_row);

      poll_return_results($id);
    }
  }
  else {
    poll_return_results($id);
  }
}

poll_submit() takes the form submission, checks if the client has already voted, and then updates the DB with the vote.

These lines get the selected option’s ID, and set $id to it:

$id = $_GET['poll'] || $_POST['poll'];
$id = str_replace("opt", '', $id);

We need to check whether the option is in the DB yet:

$row = $db->selectUnique(VOTE_DB, OPT_ID, $id);

If it is in the DB (result not empty), we need to run an updateSetWhere(). If it isn’t we need to do an insert():

if (!empty($row)) {
  $new_votes = $row[OPT_VOTES]+1;
  $db->updateSetWhere(VOTE_DB, array(OPT_VOTES => $new_votes), new SimpleWhereClause(OPT_ID, '=', $id));

  poll_return_results($id);
}
else if ($options[$id]) {
  $new_row[OPT_ID] = $id;
  $new_row[OPT_TITLE] = $options[$id];
  $new_row[OPT_VOTES] = 1;
  $db->insert(VOTE_DB, $new_row);

  poll_return_results($id);
}

Either way, we need to insert the IP into the DB, and set a cookie (expires in one year):

$ip[0] = $_SERVER['REMOTE_ADDR'];
$db->insert(IP_DB, $ip);

setcookie("vote_id", $id, time()+31556926);

poll_return_results()

function poll_return_results($id = NULL) {
    global $db;

    $html = file_get_contents(HTML_FILE);
    $results_html = "<div id='poll-container'><div id='poll-results'><h3>Poll Results</h3>\n<dl class='graph'>\n";

    $rows = $db->selectWhere(VOTE_DB,
      new SimpleWhereClause(OPT_ID, "!=", 0), -1,
      new OrderBy(OPT_VOTES, DESCENDING, INTEGER_COMPARISON));

    foreach ($rows as $row) {
      $total_votes = $row[OPT_VOTES]+$total_votes;
    }

    foreach ($rows as $row) {
      $percent = round(($row[OPT_VOTES]/$total_votes)*100);
      if (!$row[OPT_ID] == $id) {
        $results_html .= "<dt class='bar-title'>". $row[OPT_TITLE] ."</dt><dd class='bar-container'><div id='bar". $row[OPT_ID] ."'style='width:$percent%;'>&nbsp;</div><strong>$percent%</strong></dd>\n";
      }
      else {
        $results_html .= "<dt class='bar-title'>". $row[OPT_TITLE] ."</dt><dd class='bar-container'><div id='bar". $row[OPT_ID] ."' style='width:$percent%;background-color:#0066cc;'>&nbsp;</div><strong>$percent%</strong></dd>\n";
      }
    }

    $results_html .= "</dl><p>Total Votes: ". $total_votes ."</p></div></div>\n";

    $results_regex = '/<div id="poll-container">(.*?)<\/div>/s';
    $return_html = preg_replace($results_regex, $results_html, $html);
    print $return_html;
}

poll_return_results() generates the poll results, takes the HTML file, replaces the form with the results, and returns the file to the client.

First, lets grab the HTML file and set $html to it:

$html = file_get_contents(HTML_FILE);

Next, we start the results HTML structure:

$results_html = "<div id='poll-container'><div id='poll-results'><h3>Poll Results</h3>\n<dl class='graph'>\n";

To create the results HTML we need to get all the rows (options) from the DB sorted by number of votes:

$rows = $db->selectWhere(VOTE_DB,
  new SimpleWhereClause(OPT_ID, "!=", 0), -1,
  new OrderBy(OPT_VOTES, DESCENDING, INTEGER_COMPARISON));

We also need the total votes to calculate percentages:

foreach ($rows as $row) {
  $total_votes = $row[OPT_VOTES]+$total_votes;
}

Next, we calculate the percentage of votes the current option has:

foreach ($rows as $row) {
  $percent = round(($row[OPT_VOTES]/$total_votes)*100);

The HTML for the results will be a definition list (<dl>) styled with CSS to create bar graphs:

$results_html .= "<dt class='bar-title'>". $row[OPT_TITLE] ."</dt><dd class='bar-container'><div id='bar". $row[OPT_ID] ."'style='width:$percent%;'>&nbsp;</div><strong>$percent%</strong></dd>\n";

Also, we should check if the current option is the one the client voted for, and change the color:

if (!$row[OPT_ID] == $id) {

}
else {
  $results_html .= "<dt class='bar-title'>". $row[OPT_TITLE] ."</dt><dd class='bar-container'><div id='bar". $row[OPT_ID] ."' style='width:$percent%;background-color:#0066cc;'>&nbsp;</div><strong>$percent%</strong></dd>\n";
}

Here, we add a total vote count and close the html tags:

$results_html .= "</dl><p>Total Votes: ". $total_votes ."</p></div></div>\n";

This is a regex that finds the poll-container <div>:

$results_regex = '/<div id="poll-container">(.*?)<\/div>/s';

The last step in this function is to replace the poll form with the results using the regex, and return the result:

$return_html = preg_replace($results_regex, $results_html, $html);
print $return_html;

poll_ajax()

function poll_ajax() {
  global $db;
  global $options;

  $id = $_GET['vote'] || $_POST['vote'];

  $ip_result = $db->selectUnique(IP_DB, 0, $_SERVER['REMOTE_ADDR']);

  if (empty($ip_result)) {
    $ip[0] = $_SERVER['REMOTE_ADDR'];
    $db->insert(IP_DB, $ip);

    if ($id != 'none') {
      $row = $db->selectUnique(VOTE_DB, OPT_ID, $id);
      if (!empty($row)) {
        $new_votes = $row[OPT_VOTES]+1;

        $db->updateSetWhere(VOTE_DB, array(OPT_VOTES => $new_votes), new SimpleWhereClause(OPT_ID, '=', $id));
      }
      else if ($options[$id]) {
        $new_row[OPT_ID] = $id;
        $new_row[OPT_TITLE] = $options[$id];
        $new_row[OPT_VOTES] = 1;
        $db->insert(VOTE_DB, $new_row);
      }
    }
  }

  $rows = $db->selectWhere(VOTE_DB, new SimpleWhereClause(OPT_ID, "!=", 0), -1, new OrderBy(OPT_VOTES, DESCENDING, INTEGER_COMPARISON));
  print json_encode($rows);
}

poll_ajax() takes a request from the Javascript, adds the vote to the DB, and returns the results as JSON.

There are a few lines of code that are different from poll_submit(). The first checks if the Javascript just wants the results, and no vote should be counted:

if ($id != 'none')

The other two lines select the whole DB and return it as JSON:

$rows = $db->selectWhere(VOTE_DB, new SimpleWhereClause(OPT_ID, "!=", 0), -1, new OrderBy(OPT_VOTES, DESCENDING, INTEGER_COMPARISON));
print json_encode($rows);

CSS

.graph {
  width: 250px;
  position: relative;
  right: 30px;
}
.bar-title {
  position: relative;
  float: left;
  width: 104px;
  line-height: 20px;
  margin-right: 17px;
  font-weight: bold;
  text-align: right;
}
.bar-container {
  position: relative;
  float: left;
  width: 110px;
  height: 10px;
  margin: 0px 0px 15px;
}

.bar-container div {
  background-color:#cc4400;
  height: 20px;
}
.bar-container strong {
  position: absolute;
  right: -32px;
  top: 0px;
  overflow: hidden;
}
#poll-results p {
  text-align: center;
}
Poll Results

This CSS styles the results returned by the PHP or Javascript.

  • .graph styles the container for the bars, titles and percentages. The width will be different for each site.
  • .bar-title styles the titles for the bar graphs.
  • .bar-container styles the individual bar and percentage containers
  • .bar-container div styles the div that the bar is applied to. To create the bars, a percentage width is set with PHP or Javascript.
  • .bar-container strong styles the percentage.
  • #poll-results p styles the total votes.

Javascript

Introduction

The Javascript will intercept the submit button, send the vote with Ajax, and animate the results.

First, some global variables. You should recognize the first three from the PHP. votedID stores the ID of the option the client voted for.

var OPT_ID = 0;
var OPT_TITLE = 1;
var OPT_VOTES = 2;

var votedID;

Now we need a jQuery ready function which runs when the page loads:

$(document).ready(function(){

Inside that function we register the handler for the vote button which will run formProcess when it is triggered:

$("#poll").submit(formProcess);

We also need to check if the results <div> exists, and animate the results if it does:

if ($("#poll-results").length > 0 ) {
    animateResults();
}

If we have a cookie we should jump straight to generating the results because the user has already voted. To do that we need to get rid of the poll form, get the id from the cookie, grab the results from the PHP and pass them to loadResults().

if ($.cookie('vote_id'))
    $("#poll-container").empty();
    votedID = $.cookie('vote_id');
    $.getJSON("poll.php?vote=none",loadResults);
}

formProcess()

function formProcess(event){
  event.preventDefault();

  var id = $("input[@name='poll']:checked").attr("value");
  id = id.replace("opt",'');

  $("#poll-container").fadeOut("slow",function(){
    $(this).empty();

    votedID = id;
    $.getJSON("poll.php?vote="+id,loadResults);

    $.cookie('vote_id', id, {expires: 365});
    });
}

formProcess() is called by the submit event which passes it an event object. It prevents the form from doing a normal submit, checks/sets the cookies, runs an Ajax submit instead, then calls loadResults() to convert the results to HTML.

First, we need to prevent the default action (submitting the form):

event.preventDefault();

Next, we get the ID from the currently selected option:

var id = $("input[@name='poll']:checked").attr("value");
id = id.replace("opt",'');

input[@name='poll']:checked is a jQuery selector that selects a <input> with an attribute of name='poll' that is checked. attr("value") gets the value of the object which in our case is optn where n is the ID of the option.

Now that we have the ID, we can process it. To start, we fade out the poll form, and setup an anonymous function as a callback that is run when the fade is complete. Animations don’t pause the script, so weird things happen if you don’t do it this way.

$("#poll-container").fadeOut("slow",function(){

After it has faded out we can delete the form from the DOM using empty():

$(this).empty();

In this case, $(this) is jQuery shorthand for the DOM element that the fade was applied to.

jQuery has some other shortcut functions, including $.getJSON() which does GET request for a JSON object. When we have the object, we call loadResults() with it:

$.getJSON("poll.php?vote="+id,loadResults);

The last thing to do is set the cookie:

$.cookie('vote_id', id, {expires: 365});

loadResults()

function loadResults(data) {
  var total_votes = 0;
  var percent;

  for (id in data) {
    total_votes = total_votes+parseInt(data[id][OPT_VOTES]);
  }

  var results_html = "<div id='poll-results'><h3>Poll Results</h3>\n<dl class='graph'>\n";
  for (id in data) {
    percent = Math.round((parseInt(data[id][OPT_VOTES])/parseInt(total_votes))*100);
    if (data[id][OPT_ID] !== votedID) {
      results_html = results_html+"<dt class='bar-title'>"+data[id][OPT_TITLE]+"</dt><dd class='bar-container'><div id='bar"+data[id][OPT_ID]+"'style='width:0%;'>&nbsp;</div><strong>"+percent+"%</strong></dd>\n";
    } else {
      results_html = results_html+"<dt class='bar-title'>"+data[id][OPT_TITLE]+"</dt><dd class='bar-container'><div id='bar"+data[id][OPT_ID]+"'style='width:0%;background-color:#0066cc;'>&nbsp;</div><strong>"+percent+"%</strong></dd>\n";
    }
  }

  results_html = results_html+"</dl><p>Total Votes: "+total_votes+"</p></div>\n";

  $("#poll-container").append(results_html).fadeIn("slow",function(){
    animateResults();});
}

loadResults() is called by $.getJSON() and is passed a JSON object containing the results DB. It is pretty much the same as it’s PHP counterpart poll_return_results() with a few exceptions. The first difference is that we set the width on all the bars to 0% because we will be animating them. The other difference is that we are using a jQuery append() instead of regex to show the results. After the results fade in, the function calls animateResults().

animateResults()

function animateResults(){
  $("#poll-results div").each(function(){
      var percentage = $(this).next().text();
      $(this).css({width: "0%"}).animate({
                width: percentage}, 'slow');
  });
}

animateResults() iterates through each of the bars and animates the width property based on the percentage.

each() is a jQuery function that iterates through each element that is selected:

$("#poll-results div").each(function(){

First, we set the percentage to the text of the element next to the bar which is the <strong> containing the percentage.

var percentage = $(this).next().text();

Then we make sure the width is set to 0%, and animate it:

$(this).css({width: "0%"}).animate({
  width: percentage}, 'slow');

Tags: jQuery
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Pingback: 50 Useful New jQuery Techniques and Tutorials | Vn Sharing

  • Pingback: Kỹ thuật lập trình .com » Jquery Effect » 55 Jquery Tutorials, Resources, Tips And Tricks: Ultimate Collection

  • Pingback: Kỹ thuật lập trình .com » Jquery Effect » 45 Useful jQuery Tutorials And Techniques For Better UI

  • Nadir

    Hi,
    In the demo all is fine but the results are not displayed et all. Is there any specific reason why no results are displayed.

    Thanks.

  • Pingback: 50 Useful New jQuery Techniques and Tutorials : Vn Sharing

  • Pingback: E-sitesweb » HTML

  • Pingback: E-sitesweb » CSS

  • Pingback: E-sitesweb » formProcess

  • Pingback: 35+ Useful Ajax Tutorials for Web Developers « CSS Tips

  • Haymouth

    This would be so cool if it actually worked! The results don’t show up in the downloaded demo.

  • Pingback: MySQL databases, php forms, & dynamic results, oh my! | Randomness

  • shesha

    nice example…but have a small doubt shuld we create any table in the database……..

    • MArty

      It’s not working , I give up~

  • Pingback: 35+ Useful Ajax Tutorials for Web Developers | Tutorials Palace

  • Pingback: 10 Tutoriais de JQuery Fantásticos

  • http://giamsatgps.vn gps

    Why still use flat file DB instead of SQLite?
    Not only the use of DBMS is more convenience than flat file, but also it is easier to understand.
    Thanks for useful tutorial!

  • Alpner

    After more than 15h of work. It works! I don’t know how, but it works! :)

  • James

    Is there anything similar in Classic ASP?

  • Pingback: [Kỹ thuật web] 50 Kỹ Thuật và Bài Học về jQuery « LongKenj's Blog

  • GWIT

    Hi thanks for this great code. I m quiet a beginner in Jquery, and especially Jquery plugins and I would like to know if it’s possible and how it’s possible to transform your JS funtion into a plugin, I mean make

    $(document).ready(function(){
    $(“#poll”).submit(formProcess); // setup the submit handler

    if ($(“#poll-results”).length > 0 ) {
    animateResults();
    }

    if ($.cookie(‘vote_id’)) {
    $(“#poll-container”).empty();
    votedID = $.cookie(‘vote_id’);
    $.getJSON(“poll.php?vote=none”,loadResults);
    }
    });

    which is applicable only to elements ” $(“#poll”)” to a borader element : “this”, which is from what i understood the principle of a plugins. Thanks.

    • http://www.tutsplus.com TutCommenter

      Yes it is possible. Do it and share it with us.

  • Grayson

    Throughout 200-something comments I don’t see where anyone has this working … myself included. Am I wrong? I get the same as all others: no update of vote.txt. Permissions usually make users oversee the obvious. Data directory 777 txt files 755, 644 and everything in between. All main files 644. Zippo, nada, nil, nothign to update vote.txt. Anyone looking at this script should read the unanswered posts before making the effort.

  • http://www.leatherjacketmedia.com Matt

    Hey Guys,

    This Poll DOES work and after fighting with it for hours, I figured out the problems and I’ll share them here so all of you can get it working. The fact that is uses a flat file (no database) and that it stores a cookie makes this one of the easiest compact polls out there which is why we’re all craving to get this working.

    So — here’s what I did:

    1) I’m not sure if it’s really necessary, but following one of the posts above, I edited poll.php as follows:

    Replace: $id = $_GET['vote'] || $_POST['vote'];
    With: $id = isset($_GET['vote']) ? $_GET['vote'] : $_POST['vote'];

    and

    Replace: $id = $_GET['poll'] || $_POST['poll'];
    With: $id = isset($_GET['poll']) ? $_GET['poll'] : $_POST['poll'];

    Add a closing ?> tag in poll.php

    2) Edit poll.php with your preferred poll questions. This is pretty obvious.

    3) Edit the votes.txt file to represent your poll answers. The info here does NOT have to be the same text as your poll questions. You can abbreviate or alter if necessary, but you DO need the ID number in front of the poll answer and you MUST have a vote count as a starting place, so maybe use 1 for everything. Also, because of the way text files are encoded, use a TAB to separate your ID, answer, and vote count.

    Most of you should know this already, but do NOT edit this file with Microsoft word. You must use Dreamweaver, Apple’s Text Edit (in plain text mode), or Window’s notepad. For those unaware, using other text editing programs embed hidden things you can’t see which make the file difficult to read and function. Use a very basic text editor! Keep this in mind for future projects, young bucks!

    4) HERE’S THE KICKER I DISCOVERED and I suspect this is the problem most of you had in not getting poll results. When you edit the vote.txt file with your ID number, answer, and vote count, be sure there are NO trailing spaces after the last entry. If you have ANYTHING after the last entry, the voting results will fail.

    If these answers don’t get it working for you, I suggest checking your permissions of the folders and files and see if you need to set the DATA folder to 755 or 777.

    Yes, you can send your Ducati’s, racing jackets, and gear to me in gratitude. lol

  • Juve Colunga

    Hello, thnks a lot for this tutorial, i would like to know, is there some how can i share the choice or (and) result on facebook or do a twitt about it?

    thnks!!!!

  • Pingback: jquery & php poll in Blogger

  • Pingback: 30 Fresh AJAX Tutorials with jquery examples | codingquery.com

  • Pingback: 25+ AJAX Tutorials And Techniques with download for Web developer | Blog for designers web developers bloggers freelancers SEO

  • Pingback: 30 New AJAX Tutorials And Techniques | NingtecH.com - Technology News

  • Pingback: 30 Fresh AJAX Tutorials And Techniques - Design Freebies

  • Pingback: 20 Fresh AJAX Tutorials And Techniques | Web Design Core

  • http://www.abhilashraj.com Abhilash Raj R.S

    is it free to use in commercial projects

  • Pingback: 30+ Best JQuery Tutorials | ThemesPress

  • Pingback: 开发者经常用到的75 个功能强大的 jQuery插件和教程汇总(上篇) - TNM博客 - 知其然知其所以然 | 做而且还要做好 | 知足常乐

  • Pingback: 我收集到的最新的AJAX教程和技术(下篇) | 编程·早晨

  • suresh

    i am getting this error. Declaration of LikeWhereClause::testRow() should be compatible with WhereClause::testRow($row, $rowSchema = NULL) in D:\wamp\www\dynamic_poll\flatfile.php on line 568.
    How to solve this.

  • cmaaga

    I need show results in another page (not inside index.html) or I need button to back for poll. Any idea?

  • http://www.webheadz.ie ronan

    Hi…is there a way i could change this code so to let a user create there own poll???

  • Maarten

    it still isnt working for me :’( results arent coming on ive tried everthing on the comments.. please help

  • Pingback: 12+ Helpful AJAX Tutorials And Resources To Learn - Tutorials-Share.com

  • Nurr

    Damn, I think i’ve read all the comms, but i cant find any solution. IPs it’s ok, but VOTE txt isn’t refreshing. Anybody is around here still?

    • Nurr

      I don’t know what are the author trying to say with this: “but you DO need the ID number in front of the poll answer and you MUST
      have a vote count as a starting place, so maybe use 1 for everything.
      Also, because of the way text files are encoded, use a TAB to separate
      your ID, answer, and vote count.”

      What’s the ID number?? What’s the votes.txt structure???

  • vad

    in the latest version of jquery poll will not work – must be replaced by a single character in poll.js:
    old: var id = $(“input[@name='poll']:checked”).attr(“value”);
    new: var id = $(“input[name='poll']:checked”).attr(“value”);

    http://jamesallen.name/index.cfm/2009/3/12/JQuery-selector-problem–Syntax-error-unrecognized-expression-fix

  • Kevin Short

    An excellent 5, 7 and 10 Star Rating System – Saves user ratings in a text file by default but is also set up for MySql database. Three scripts included.

    Also find an Up or Down Voting System.

    http://templatz.co/rating-voting-scripts.php

  • Guest

    Edit poll.php

    change: $id = $_GET['vote'] || $_POST['vote']; to $id = $_GET['vote'] || $_POST['vote'];

    and $id = $_GET['poll'] || $_POST['poll']; to $id = isset($_GET['poll']) ? $_GET['poll'] : $_POST['poll'];

    add error_reporting(0); after close tag

    it do works.. hope it help..