{"id":802,"date":"2011-04-10T22:43:19","date_gmt":"2011-04-11T05:43:19","guid":{"rendered":"http:\/\/virendrachandak.wordpress.com\/?p=13"},"modified":"2016-03-20T12:23:07","modified_gmt":"2016-03-20T19:23:07","slug":"voting-functionality-in-a-website","status":"publish","type":"post","link":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/","title":{"rendered":"Voting Functionality in a website"},"content":{"rendered":"<p>In this post I will give the step by step explanation of how we can add Voting Functionality to a website. At the end of this article we will have a working sample voting application. The source code for the sample voting application can be downloaded from <a href=\"http:\/\/www.box.net\/shared\/zilt2dacty\" target=\"_blank\">here<\/a>.<\/p>\n<p>We will be using PHP, MySQL, jQuery, HTML, CSS, AJAX to implement this.<\/p>\n<p>To setup this functionality we will have to first setup database, then a front-end and also a page which would actually record and retrieve the votes.<br \/>\n<!--more--><\/p>\n<div><span style=\"text-decoration:underline;\"><strong>Step 1<\/strong><\/span>: Setup Database: We can have a table with following schema:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nCREATE TABLE `votes` (\r\n  `vote_id` INT NOT NULL AUTO_INCREMENT ,\r\n  `item_id` INT NOT NULL ,\r\n  `user_id` INT NOT NULL ,\r\n  `datetime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,\r\n  `ipaddress` INT( 10 ) NOT NULL ,\r\nPRIMARY KEY ( `vote_id` )\r\n) ENGINE = MYISAM ;\r\n<\/pre>\n<p>Description of the fields of the table:<\/p>\n<ul>\n<li>vote_id &#8211; Auto-increment count of votes.<\/li>\n<li>item_id &#8211; ID of the item on which voting is being done, e.g. an article or a picture. In these cases the item_id can be article_id or picture_id respectively.<\/li>\n<li>user_id &#8211; The user_id of the user who is voting. This field can be used to track which user has voted how many times.<\/li>\n<li>datetime &#8211; The time-stamp at which the vote was recorded.<\/li>\n<li>ipaddress &#8211; The ipaddress of the user who has voted. This field is optional, depending on use. I have added this so that I can restrict number of votes from same ipaddress.<\/li>\n<\/ul>\n<p>We can also have an option store different kinds of votes e.g. likes and dislikes. For this, we will need to add another field in the votes table to indicate the type of vote.<\/p>\n<p>We can use the following SQL statement to add that field to the above table.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nALTER TABLE `votes`\r\nADD `vote_type` ENUM( 'like', 'dislike' )\r\nNOT NULL DEFAULT 'like' ;\r\n<\/pre>\n<\/div>\n<div><span style=\"text-decoration:underline;\"><strong>Step 2<\/strong><\/span>: Front-end setup: On the webpage we will require a button which can be clicked in-order to vote.<\/p>\n<p>For vote button we will an image and handle its onclick event using JavaScript or jQuery. We can also use some text instead of image.<\/p>\n<p><span style=\"text-decoration:underline;\">CSS<\/span><\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#vote_button { background: url('vote.png') no-repeat scroll 0 0 transparent; cursor: pointer; height: 25px; width: 95px; }\r\n#vote_count { padding: 8px 0pt 0pt 30px; }\r\n<\/pre>\n<p><span style=\"text-decoration:underline;\">HTML<\/span><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!-- Div for vote button and number of votes --&gt;\r\n&lt;div id=&quot;vote_already&quot; style=&quot;display: none;&quot;&gt;Your have already voted.&lt;\/div&gt;\r\n&lt;pre&gt;&lt;\/pre&gt;\r\n&lt;div id=&quot;vote_recorded&quot; style=&quot;display: none;&quot;&gt;Thanks for your vote!&lt;\/div&gt;\r\n<\/pre>\n<p>The above HTML code will display the vote button and vote count. You should replace &#8216;vote.png&#8217; with the path of the vote image you want to use. Also, you may have to adjust the CSS of vote_button and vote_count according to your requirements.<\/p>\n<\/div>\n<div><span style=\"text-decoration:underline;\"><strong>Step 3<\/strong><\/span>: Handling the vote_button onclick event: In order to record the vote we will have to handle the click even on it. We can use JavaScript or jQuery for it.<span style=\"text-decoration:underline;\">Using jQuery<\/span>:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$(&quot;#vote_button&quot;).click(function()\r\n{\r\n    \/\/ Code for handling the click event.\r\n});\r\n<\/pre>\n<p><span style=\"text-decoration:underline;\">Note<\/span>: If you are using jQuery you will have to include the jQuery library. You can host the jQuery library on your website or use some already hosted file like <a href=\"http:\/\/code.google.com\/apis\/libraries\/devguide.html#jquery\" target=\"_blank\" rel=\"external nofollow\">Google Library API<\/a>. Use the following code to include the jQuery library<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">&lt;script type=&quot;text\/javascript&quot; src=&quot;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.5.1\/jquery.min.js&quot;&gt;&lt;\/script&gt;\r\n<\/pre>\n<\/div>\n<div><span style=\"text-decoration:underline;\"><strong>Step 4<\/strong><\/span>: Recording Votes: To record votes we have various options. We can just reload the page and record the vote or we can use AJAX to record the vote. Using AJAX is a better option because the user would not have to wait until the page is reloaded. It also increases the user experience. We will have to pass some data to a page on the server which would record the vote and respond whether the vote has been recorded successfully or not and updated vote count. Let us use a PHP page on the server-side called &#8220;ajax_vote.php&#8221;.<span style=\"text-decoration:underline;\">The AJAX request<\/span>:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$(&quot;#vote_button&quot;).click(function()\r\n{\r\n\tvar item_id = 1;\t\/\/ This is the item_id for which the number of votes are to be displayed.\r\n\tvar user_id = 1;\t\/\/ This is the user_id who is voting.\r\n\tvar ajax_data = &quot;query=vote&amp;amp;item_id=&quot; + item_id + &quot;&amp;amp;user_id=&quot; + user_id;\r\n\t$.ajax({\r\n\t\ttype: &quot;GET&quot;,\r\n\t\turl: &quot;vote.php&quot;,\r\n\t\tdata: ajax_data,\r\n\t\tdataType: &quot;html&quot;,\r\n\t\tsuccess: function(votecount){\r\n\t\t\tif(votecount == -1){\r\n\t\t\t\t\/\/ The user has already voted.\r\n\t\t\t\t$(&quot;#vote_recorded&quot;).css({ display:'none' });\r\n\t\t\t\t$(&quot;#vote_already&quot;).css({ display:'' });\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t\/\/ Vote recorded, display the updated count.\r\n\t\t\t\t$(&quot;#vote_already&quot;).css({ display:'none' });\r\n\t\t\t\t$(&quot;#vote_count&quot;).html(votecount);\r\n\t\t\t\t$(&quot;#vote_recorded&quot;).css({ display:'' });\r\n\t\t\t}\r\n\t\t}\r\n\t});\r\n});\r\n<\/pre>\n<p><span style=\"text-decoration:underline;\">Note<\/span>: I am using jQuery AJAX method because it&#8217;s very easy to use. Alternatively you can use JavaScript for AJAX.<\/p>\n<\/div>\n<div><span style=\"text-decoration:underline;\"><strong>Step 5<\/strong><\/span>: Handling the AJAX request on Server: Now we have the database and front-end completed. We just have to handle the requests on the server and send the response. So now we will write the code in the &#8220;ajax_vote.php&#8221; file.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/ $con is the connection variable to the database\r\nif($_GET&#x5B;'query'] == 'vote')\r\n{\r\n\t$item_id = $_GET&#x5B;'item_id'];\r\n\t$user_id = $_GET&#x5B;'user_id'];\r\n\t$ip_addr = $_SERVER&#x5B;'REMOTE_ADDR'];\r\n\t\/\/ Check for entry in Database to see if the user has already voted\r\n\t$sql = &quot;SELECT vote_id FROM votes WHERE ipaddress = &quot;. ip2long($ip_addr) . &quot; AND user_id = &quot; . $user_id .&quot; AND item_id = &quot; . $item_id . &quot; LIMIT 1&quot;;\r\n\t$votes = mysql_query($sql, $con);\r\n\t$already_voted = false;\r\n\twhile ($row = mysql_fetch_array($votes))\r\n\t{\r\n\t\t$already_voted = true;\r\n\t}\r\n\tif($already_voted)\r\n\t{\r\n\t\techo -1;\r\n\t}\r\n\telse\r\n\t{\r\n\t\t$sql = &quot;INSERT INTO votes (item_id, user_id, ipaddress) VALUES (&quot; . $item_id . &quot;, &quot;. $user_id . &quot;, &quot;. ip2long($ip_addr) . &quot;)&quot;;\r\n\t\tmysql_query($sql, $con);\r\n\t\t\/\/ Get updated vote count.\r\n\t\t$total_votes = 0;\r\n\t\t$total_votes = mysql_query(&quot;SELECT COUNT(vote_id) as total FROM votes WHERE item_id = &quot;. $item_id . &quot; LIMIT 1&quot;, $con);\r\n\t\twhile($row = mysql_fetch_array($total_votes))\r\n\t\t{\r\n\t\t\techo $row&#x5B;'total'];\r\n\t\t}\r\n\t}\r\n}\r\nelse if($_GET&#x5B;'query'] == 'votecount')\r\n{\r\n\t$item_id = $_GET&#x5B;'item_id'];\r\n\t$total_votes = 0;\r\n\t$total_votes = mysql_query(&quot;SELECT COUNT(vote_id) as total FROM votes WHERE item_id = &quot;. $item_id . &quot; LIMIT 1&quot;, $con);\r\n\twhile($row = mysql_fetch_array($total_votes))\r\n\t{\r\n\t\techo $row&#x5B;'total'];\r\n\t}\r\n}\r\n<\/pre>\n<p>The above code will record the vote and send a response whether the vote has been recorded or not and the updated count. if we et -1 that means the vote was not recorded. Any other value implies the vote was recorded and the value will be equal to the number of votes.<\/p>\n<\/div>\n<div><span style=\"text-decoration:underline;\"><strong>The complete code<\/strong><\/span>:<\/p>\n<p><span style=\"text-decoration:underline;\"><strong>DATABASE Queries<\/strong><\/span>:<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nCREATE TABLE `votes` (\r\n    `vote_id` INT NOT NULL AUTO_INCREMENT ,\r\n    `item_id` INT NOT NULL ,\r\n    `user_id` INT NOT NULL ,\r\n    `datetime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,\r\n    `ipaddress` INT( 10 ) NOT NULL ,\r\n    PRIMARY KEY ( `vote_id` )\r\n) ENGINE = MYISAM ;\r\n<\/pre>\n<p>\/\/ If we use this we will have to change the queries in the PHP file. Also will have to change the data passed to the file via ajax.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nALTER TABLE `votes`\r\nADD `vote_type` ENUM( 'like', 'dislike' )\r\nNOT NULL DEFAULT 'like' ;\r\n<\/pre>\n<p><span style=\"text-decoration:underline;\"><strong>CSS CODE<\/strong><\/span>:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n#vote_button { background: url('vote.png') no-repeat scroll 0 0 transparent; cursor: pointer; height: 25px; width: 95px; }\r\n#vote_count { padding: 8px 0pt 0pt 30px; }\r\n<\/pre>\n<p><span style=\"text-decoration:underline;\"><strong>HTML CODE<\/strong><\/span>:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!-- Div for vote button and number of votes --&gt;\r\n&lt;div id=&quot;vote_already&quot; style=&quot;display: none;&quot;&gt;Your have already voted.&lt;\/div&gt;\r\n&lt;pre&gt;&lt;\/pre&gt;\r\n&lt;div id=&quot;vote_recorded&quot; style=&quot;display: none;&quot;&gt;Thanks for your vote!&lt;\/div&gt;\r\n&lt;pre&gt;<\/pre>\n<p><span style=\"text-decoration:underline;\"><strong>JavaScript\/jQuery CODE<\/strong><\/span>:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$(document).ready(function()\r\n{\r\n\t\/\/ Display number of votes for this item on page load.\r\n\tvar item_id = 1;\t\/\/ This is the item_id for which the number of votes are to be displayed.\r\n\tvar ajax_data1 = &quot;query=votecount&amp;amp;item_id=&quot; + item_id;\r\n\tjQuery.ajax({\r\n\t\ttype: &quot;GET&quot;,\r\n\t\turl: &quot;vote.php&quot;,\r\n\t\tdata: ajax_data1,\r\n\t\tdataType: &quot;html&quot;,\r\n\t\tsuccess: function(html){\r\n\t\t\tjQuery(&quot;#vote_count&quot;).html(html);\r\n\t   }\r\n\t});\r\n});\r\n$(&quot;#vote_button&quot;).click(function()\r\n{\r\n\tvar item_id = 1;\t\/\/ This is the item_id for which the number of votes are to be displayed.\r\n\tvar user_id = 1;\t\/\/ This is the user_id who is voting.\r\n\tvar ajax_data = &quot;query=vote&amp;amp;item_id=&quot; + item_id + &quot;&amp;amp;user_id=&quot; + user_id;\r\n\t$.ajax({\r\n\t\ttype: &quot;GET&quot;,\r\n\t\turl: &quot;vote.php&quot;,\r\n\t\tdata: ajax_data,\r\n\t\tdataType: &quot;html&quot;,\r\n\t\tsuccess: function(votecount){\r\n\t\t\tif(votecount == -1){\r\n\t\t\t\t\/\/ The user has already voted.\r\n\t\t\t\t$(&quot;#vote_recorded&quot;).css({ display:'none' });\r\n\t\t\t\t$(&quot;#vote_already&quot;).css({ display:'' });\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\t\/\/ Vote recorded, display the updated count.\r\n\t\t\t\t$(&quot;#vote_already&quot;).css({ display:'none' });\r\n\t\t\t\t$(&quot;#vote_count&quot;).html(votecount);\r\n\t\t\t\t$(&quot;#vote_recorded&quot;).css({ display:'' });\r\n\t\t\t}\r\n\t\t}\r\n\t});\r\n});\r\n<\/pre>\n<p><span style=\"text-decoration:underline;\"><strong>PHP CODE<\/strong><\/span>:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/ $con is the connection variable to the database\r\nif($_GET&#x5B;'query'] == 'vote')\r\n{\r\n\t$item_id = $_GET&#x5B;'item_id'];\r\n\t$user_id = $_GET&#x5B;'user_id'];\r\n\t$ip_addr = $_SERVER&#x5B;'REMOTE_ADDR'];\r\n\t\/\/ Check for entry in Database to see if the user has already voted\r\n\t$sql = &quot;SELECT vote_id FROM votes WHERE ipaddress = &quot;. ip2long($ip_addr) . &quot; AND user_id = &quot; . $user_id .&quot; AND item_id = &quot; . $item_id . &quot; LIMIT 1&quot;;\r\n\t$votes = mysql_query($sql, $con);\r\n\t$already_voted = false;\r\n\twhile ($row = mysql_fetch_array($votes))\r\n\t{\r\n\t\t$already_voted = true;\r\n\t}\r\n\tif($already_voted)\r\n\t{\r\n\t\techo -1;\r\n\t}\r\n\telse\r\n\t{\r\n\t\t$sql = &quot;INSERT INTO votes (item_id, user_id, ipaddress) VALUES (&quot; . $item_id . &quot;, &quot;. $user_id . &quot;, &quot;. ip2long($ip_addr) . &quot;)&quot;;\r\n\t\tmysql_query($sql, $con);\r\n\t\t\/\/ Get updated vote count.\r\n\t\t$total_votes = 0;\r\n\t\t$total_votes = mysql_query(&quot;SELECT COUNT(vote_id) as total FROM votes WHERE item_id = &quot;. $item_id . &quot; LIMIT 1&quot;, $con);\r\n\t\twhile($row = mysql_fetch_array($total_votes))\r\n\t\t{\r\n\t\t\techo $row&#x5B;'total'];\r\n\t\t}\r\n\t}\r\n}\r\nelse if($_GET&#x5B;'query'] == 'votecount')\r\n{\r\n\t$item_id = $_GET&#x5B;'item_id'];\r\n\t$total_votes = 0;\r\n\t$total_votes = mysql_query(&quot;SELECT COUNT(vote_id) as total FROM votes WHERE item_id = &quot;. $item_id . &quot; LIMIT 1&quot;, $con);\r\n\twhile($row = mysql_fetch_array($total_votes))\r\n\t{\r\n\t\techo $row&#x5B;'total'];\r\n\t}\r\n}\r\n<\/pre>\n<\/div>\n<div><a href=\"http:\/\/www.box.net\/shared\/zilt2dacty\" target=\"_blank\">Click here<\/a> to download a sample voting application.<\/div>\n<div><strong>Update<\/strong>: Here are the screenshots of how the sample application would look.<\/p>\n<p><span style=\"text-decoration:underline;\">Initial<\/span>: This is how the page would look initially.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-384\" style=\"border:1px solid#000;\" title=\"Initial\" src=\"https:\/\/i0.wp.com\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/initial.png?resize=165%2C55\" alt=\"\" width=\"165\" height=\"55\" \/><\/p>\n<p><span style=\"text-decoration:underline;\">After voting for the first time<\/span>: When you vote for the first time you will see the following.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-385\" style=\"border:1px solid#000;\" title=\"After voting for the first time\" src=\"https:\/\/i0.wp.com\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/after-voting.png?resize=165%2C55\" alt=\"\" width=\"165\" height=\"55\" \/><\/p>\n<p><span style=\"text-decoration:underline;\">Trying to revote<\/span>: If you have already voted, and you try to vote again, you will get the following:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-387\" style=\"border:1px solid#000;\" title=\"Trying to revote\" src=\"https:\/\/i0.wp.com\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/trying-to-revote.png?resize=165%2C55\" alt=\"Trying to revote\" width=\"165\" height=\"55\" \/><\/p>\n<\/div>\n<div><span style=\"text-decoration:underline;\"><strong>Note<\/strong><\/span>: I have tested the above steps on Wampserver 2.1 using PHP 5.3.4, MySQL 5.1.53, Apache 2.2.17. Also, I have used jQuery 1.5.1 from google APIs. Having said that I do not take responsibility for proper functioning of the above mentioned steps under all circumstances. If you download any files, programs from my blog then make sure you protect yourself. I am not responsible for any damage to your computer, website, blog, application or any thing else.\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this post I will give the step by step explanation of how we can add Voting Functionality to a website. At the end of this article we will have a working sample voting application. The source code for the sample voting application can be downloaded from here. We will be using PHP, MySQL, jQuery, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3,143,8],"tags":[19,11,151,124,65,75],"class_list":["post-802","post","type-post","status-publish","format-standard","hentry","category-functionality","category-php","category-web-development","tag-ajax","tag-jquery","tag-mysql","tag-snippets","tag-table-database","tag-voting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Voting Functionality in a website - Virendra&#039;s TechTalk<\/title>\n<meta name=\"description\" content=\"In this post I will give the step by step explanation of how we can add Voting Functionality to a website. At the end of this article we will have a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Voting Functionality in a website - Virendra&#039;s TechTalk\" \/>\n<meta property=\"og:description\" content=\"In this post I will give the step by step explanation of how we can add Voting Functionality to a website. At the end of this article we will have a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/\" \/>\n<meta property=\"og:site_name\" content=\"Virendra&#039;s TechTalk\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/virendrachandak\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/virendrachandak\" \/>\n<meta property=\"article:published_time\" content=\"2011-04-11T05:43:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-03-20T19:23:07+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/initial.png\" \/>\n<meta name=\"author\" content=\"Virendra Chandak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@virendrachandak\" \/>\n<meta name=\"twitter:site\" content=\"@virendrachandak\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virendra Chandak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/\"},\"author\":{\"name\":\"Virendra Chandak\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"headline\":\"Voting Functionality in a website\",\"datePublished\":\"2011-04-11T05:43:19+00:00\",\"dateModified\":\"2016-03-20T19:23:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/\"},\"wordCount\":1923,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"image\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/initial.png\",\"keywords\":[\"Ajax\",\"jQuery\",\"MySQL\",\"snippets\",\"Table (database)\",\"Voting\"],\"articleSection\":[\"Functionality\",\"PHP\",\"Web Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/\",\"url\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/\",\"name\":\"Voting Functionality in a website - Virendra&#039;s TechTalk\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/initial.png\",\"datePublished\":\"2011-04-11T05:43:19+00:00\",\"dateModified\":\"2016-03-20T19:23:07+00:00\",\"description\":\"In this post I will give the step by step explanation of how we can add Voting Functionality to a website. At the end of this article we will have a\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/initial.png\",\"contentUrl\":\"http:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/initial.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/voting-functionality-in-a-website\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"TechTalk\",\"item\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Functionality\",\"item\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/category\\\/functionality\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Voting Functionality in a website\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#website\",\"url\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/\",\"name\":\"Virendra's TechTalk\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\",\"name\":\"Virendra Chandak\",\"logo\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.virendrachandak.com\",\"https:\\\/\\\/www.facebook.com\\\/virendrachandak\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/virendrachandak\\\/\",\"https:\\\/\\\/x.com\\\/virendrachandak\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Voting Functionality in a website - Virendra&#039;s TechTalk","description":"In this post I will give the step by step explanation of how we can add Voting Functionality to a website. At the end of this article we will have a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/","og_locale":"en_US","og_type":"article","og_title":"Voting Functionality in a website - Virendra&#039;s TechTalk","og_description":"In this post I will give the step by step explanation of how we can add Voting Functionality to a website. At the end of this article we will have a","og_url":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/","og_site_name":"Virendra&#039;s TechTalk","article_publisher":"https:\/\/www.facebook.com\/virendrachandak","article_author":"https:\/\/www.facebook.com\/virendrachandak","article_published_time":"2011-04-11T05:43:19+00:00","article_modified_time":"2016-03-20T19:23:07+00:00","og_image":[{"url":"http:\/\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/initial.png","type":"","width":"","height":""}],"author":"Virendra Chandak","twitter_card":"summary_large_image","twitter_creator":"@virendrachandak","twitter_site":"@virendrachandak","twitter_misc":{"Written by":"Virendra Chandak","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/#article","isPartOf":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/"},"author":{"name":"Virendra Chandak","@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"headline":"Voting Functionality in a website","datePublished":"2011-04-11T05:43:19+00:00","dateModified":"2016-03-20T19:23:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/"},"wordCount":1923,"commentCount":4,"publisher":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"image":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/#primaryimage"},"thumbnailUrl":"http:\/\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/initial.png","keywords":["Ajax","jQuery","MySQL","snippets","Table (database)","Voting"],"articleSection":["Functionality","PHP","Web Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/","url":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/","name":"Voting Functionality in a website - Virendra&#039;s TechTalk","isPartOf":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/#primaryimage"},"image":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/#primaryimage"},"thumbnailUrl":"http:\/\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/initial.png","datePublished":"2011-04-11T05:43:19+00:00","dateModified":"2016-03-20T19:23:07+00:00","description":"In this post I will give the step by step explanation of how we can add Voting Functionality to a website. At the end of this article we will have a","breadcrumb":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/#primaryimage","url":"http:\/\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/initial.png","contentUrl":"http:\/\/www.virendrachandak.com\/techtalk\/wp-content\/uploads\/2011\/10\/initial.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.virendrachandak.com\/techtalk\/voting-functionality-in-a-website\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"TechTalk","item":"https:\/\/www.virendrachandak.com\/techtalk\/"},{"@type":"ListItem","position":2,"name":"Functionality","item":"https:\/\/www.virendrachandak.com\/techtalk\/category\/functionality\/"},{"@type":"ListItem","position":3,"name":"Voting Functionality in a website"}]},{"@type":"WebSite","@id":"https:\/\/www.virendrachandak.com\/techtalk\/#website","url":"https:\/\/www.virendrachandak.com\/techtalk\/","name":"Virendra's TechTalk","description":"","publisher":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.virendrachandak.com\/techtalk\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17","name":"Virendra Chandak","logo":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.virendrachandak.com","https:\/\/www.facebook.com\/virendrachandak","https:\/\/www.linkedin.com\/in\/virendrachandak\/","https:\/\/x.com\/virendrachandak"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2vTtQ-cW","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/802","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/comments?post=802"}],"version-history":[{"count":0,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/802\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/media?parent=802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/categories?post=802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/tags?post=802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}