Posts

Showing posts from October, 2015

INTEGRATE BOOTSTRAP WITH PHP CODEIGNITER FRAMEWORK

Image
This tutorial is about the technique of combining the power of two robust frameworks, PHP CodeIgniter MVC framework and Twitter Bootstrap. You need to properly integrate twitter bootstrap  with CodeIgniter framework for it to work properly.  So this tutorial will show you how to integrate Bootstrap with CodeIgniter to enhance the appearance of your CodeIgniter application. Download the latest versions of the frameworks from the links given below. Download CodeIgniter Framework   Download Twitter Bootstrap  Download jQuery Steps for integration of CodeIgniter framework with bootstrap STEP-1: Download and extract the PHP CodeIgniter Framework  zip file from the above link to your Local Server. Rename it with your application name.  Inside create a folder named "assets" to keep all your bootstrap files.  CodeIgnitor folder structure must be  similar to the below image.  STEP-2:  Extract all the files of boots...

SQL query in CodeIgnitor

1 Inserting Data 1.1 $this->db->insert(); This SQL statement generates an insert string based on the data  supplied. You can either pass an array of data or an object to the function. Example of  using an array in SQL Statement: $data = array(    'sn' => 106 ,    'name' => 'Tapan' ,    'college' => 'ASCOL' ); $this->db->insert('mytablename', $data); // This SQL Statament produces: INSERT INTO mytablename (sn, name, college) VALUES (106, 'Tapan', 'ASCOL') The first parameter will contain the name of table, the second is an associative array of values. Here is an example using an object: /*     class Mydata {         var $sn = 106;         var $name = 'Tapan';         var $college = 'ASCOL';     } */ $object = new Mydata; $this->db->insert('mytablename', $object); // This SQL sta...

FORM VALIDATION IN CODEIGNITOR

Image
1. Create database employee using CREATE DATABASE employee CREATE DATABASE employee; 2.create table users using CREATE TABLE SQL statement CREATE TABLE IF NOT EXISTS `users` (   `userid` int(4) NOT NULL AUTO_INCREMENT,   `firstname` varchar(50) NOT NULL, `lastname` varchar(50) NOT NULL,   `email` varchar(50) NOT NULL,   `password` varchar(40) NOT NULL,    PRIMARY KEY (`userid`) ); 3. create a controller form.php in controller in CodeIgnitor filename: form.php <?php  defined('BASEPATH') OR exit('No direct script access allowed');      class Form extends CI_Controller{         function __construct() {             parent::__construct();      }      public function index()      {         $this->load->view('form_view');      }       ...

FORM VALIDATION

Image
Form Validation Form validation is the method/process of checking that a form input field of the form has been filled correctly by the user. For example, if your form has a box for the user to type their email address, you might want your form handler to check that they've filled in their  email address input field before you processing all the form input values in the form. It is always a good practice to validate the form before performing operation on data of the database. Types of Form Validation 1. Server Side  Validation In PHP web Programming, Server Side is usually done with ASP, PHP scripts. In Server Side Validation,the values of form input  is actually sent to server and server checks the correctness of user input values to the form. The form input values must be sent to the server for validation. So, Server side validation is slow process and often more tricky to code and it also increases load of server computer. Server Side validation i...

ADD VALUE TO CURRENT COLUMN VALUE IN CODEIGNITOR

Image
There is many times you want to add the values to the current value of column of database table. That is you want to add certain values to the current value of  database. Most of the time, we first fetch the current value and then and the value to the fetch value and finally update the database table Here is the tutorial about how to add certain value to column of the database table directly. In CodeIgnitor we can directly add value to the database column value. 1. First create a database We can create a new database using CREATE DATABASE statement. CREATE DATABASE company; 2. create a database table   We can create a new database table using CREATE TABLE  statement. CREATE TABLE IF NOT EXISTS `sales` (   `sid` int(4) NOT NULL,   `points` int(4) NOT NULL,   `section` varchar(200) NOT NULL,   `address` archar(50) NOT NULL ); 3. Insert data into table Now insert some data using INSERT INTO  operation of MY...

Selecting data from database in CodeIgnitor

Image
PHP and CodeIgnitor SQL queries allow us to  retrieve, insert and update data and information in your database. CodeIgnitor uses Active record database pattern. The values are escaped automatically by the system so it helps to produce the   safer queries . SQL queries in CodeIgnitor helps in retrieval of  data from database. The following SQL query functions allow you to build SQL  SELECT  statements. 1.1 $this->db->get(); This SQL Query is used to retrieve all the records from database. $query = $this->db->get('tableName'); // It produces SELECT * FROM table_name statement The second and third parameters in SQL query enable you to set a limit and offset clause: $query = $this->db->get('tableName', 20, 30); // Produces: SELECT * FROM tableName LIMIT 30, 20 (in MySQL.  Above SQL Query is assigned to a variable named $query, which can be used to show the results: $query = $this->db-...