Tutorials

Article Content:How to build voting Ajax system with Codeigniter part 2

How to build voting Ajax system with Codeigniter part 2

How to build voting Ajax system with Codeigniter part 2.

Hi, my fulfilling friends coming back from marriage vacation with most interesting and full passion, so I hope to make this tutorial as a gift to all followers.

I thought to complete the previous tutorial about how to create voting system or poll system from A to Z,is this sounds good?

I will also provide the full script for free, is this enough?

I will show you steps by video, and I am ready for any question, let's start.

Script features

1- voting choices is dynamic :

You can add or remove vote choices as you want, range between 1 to 10 choices for a single vote, all stores in the database

2-all votes dynamically managed:

you can add unlimited votes, edit or remove.

3-votes restricted by IP address:

To avoid votes duplicating and prevent fake voters this script uses IP address to identify voters, save their IP's in a separate table.

4- Jquery AJAX supported:

The voting process sends by AJAX, results displayed immediately, also in the backend you have the ability to add or remove choices without reloading the page by using Jquery.

5-easy to install, simple to reuse:

Code designed to be clean as possible, separated to simplify reusing and for customization purposes.

6- integrated with the bootstrap framework.

7- free to use for non-commercial or commercial projects.

 

How to install

1- Extract downloaded zip file into root As example www or htdocs

2- Rename project to 'codeIgniter-voting '

3- Create new database named as 'demo

4- Import tables files from this path application/tables to the database.

5-Go to this link Http:://locahost/codeIgniter-voting

  Enjoy dude :)

Code description

1- Controllers

Admin_voting.php

function votes_list() .. To show all votes in the admin as a list

function create() .. To create votes from admin

function edit($id) .. To edit or change created votes  from admin

function remove($id) .. To remove votes from admin

function activate_vote($id) .. To active or enable votes from admin

function deactivate_vote($id) .. To deactivate or disable votes from admin

function array_combine2($arr2) .. To remove empty choices which sent by added or edit forms and order every choice by chars from A to Z Voting.

 

Voting.php

function vote_page() .. to show the active vote

function voted($id) .. To create vote with this function, After make vote it will send by AJAX post to this function then it will check if the visitor has voted before or not.If he has voted before he will not able to vote again

 

2- Models

Voting_counter_model.php

function add_vote($id, $ip) .. to add new vote to the database

function get_one_active() ..Get the current active vote
function get_all_columns_active().. Get all choices related to active vote

function result($id).. This function gets result of specified voting by join the ci_voting table and ci_voting_counter table.

function getNumVoting($id).. Get total number of voting one

function check_ip($id, $ip) .. To check voter is voted before to this vote by check voter IP and the vote id.

 

Voting_model.php

 All this functions to handle admin

function create($orderd_data)

function update($orderd_data,$id)

function delete($id)

function active($id)

function deactivate($id)

function get_one($id)

function get_votes()

 

3- Views

// for admin list view

Content/votes_list.php

Content/voting_edit.php

Content /voting_new.php

 

// for frontend page

Content /vote_detail.php

Content /vote_page.php

Content /vote_result_current.php

5- Database tables

tables/ci_voting.sql .. to save voting chocises

CREATE TABLE IF NOT EXISTS `ci_voting` (
  `dv_id` int(11) NOT NULL AUTO_INCREMENT,
  `dv_title` varchar(255) NOT NULL,
  `A` varchar(255) NOT NULL,
  `B` varchar(255) NOT NULL,
  `C` varchar(255) NOT NULL,
  `D` varchar(255) NOT NULL,
  `E` varchar(255) NOT NULL,
  `F` varchar(255) NOT NULL,
  `G` varchar(255) NOT NULL,
  `H` varchar(255) NOT NULL,
  `I` varchar(255) NOT NULL,
  `j` varchar(255) NOT NULL,
  `dv_state` tinyint(1) DEFAULT '0',
  `dv_created` int(11) NOT NULL,
  PRIMARY KEY (`dv_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=88 ;

tables/ci_voting_counter.sql .. to save how many votes per voting

CREATE TABLE IF NOT EXISTS `ci_voting_counter` (
  `v_id` int(11) NOT NULL AUTO_INCREMENT,
  `v_voting_id` int(11) NOT NULL,
  `v_column` varchar(255) NOT NULL,
  `v_data` varchar(255) NOT NULL,
  `v_value` int(1) NOT NULL DEFAULT '1',
  `v_vistor_ip` varchar(255) NOT NULL,
  `v_created` int(11) NOT NULL,
  PRIMARY KEY (`v_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=26 ;

Conclusion

Finally, I hope all my followers enjoy to read this tutorial and to be useful for any developer in our PHP community even if he has not been a Codeigniter developer because I always repeated this words:

Understand the logic and do it anyway

Also, as I promised I put full script link in the bottom to download with short but consistent video and real demo to try yourself.

Don't hesitate to ask questions will be happy to see your comments, bye

 

Backend demo  Frontend demo

Download Link



Leave a Reply

Your email address will not be published.


Notify me of followup comments via e-mail.
You can also Subscribe without commenting.