We will try to create a simple voting system app similar to StackOverflow.com using AngularJS, PHP and MySQL. I will put the code to download as well as a demonstration of the end product as we approach the finishing point of the AngularJS Web App. This app will accept vote from users and store it into MySQL database using PHP.
The file structure of our app will be following
- angular-voting/index.html [The main file]
- angular-voting/ajax [Server side php code is kept here]
- angular-voting/app [The angularjs application code will be saved here]
- angular-voting/css [The required stylesheet file just for styling our application using Bootstrap]
- angular-voting/includes [The required configuration files like database connection infotmation, constants]
Lets first set up the database.
Download the source code and import angular-voting.sql to your MySQL database.
The database we will be using is a simple one. We just want to keep the blog post information and the voteCount. We give the table a simple name “posts“.
This contains all the posts information with voteCount.
Get posts (php)
Update Post (PHP)
Now lets move on to the angularjs file (app/app.js) which contains the little lines of code that gets the data from the server updates the view and displays the result in web browser
The index.html file which is our front end and displayed to the user