CodeIgniter

Create New Module:

1). Add Entry in module table.

2). Set permission in permission table.

3). Register in autoload file Module & Language.CI DB example – 14-2-14

___________________________________________________________________________________________________________________

Image Upload

http://www.codersmount.com/2012/11/upload-image-and-create-multiple-thumbnail-sizes-in-codeigniter/

__________________________________________________________________________________________________________________

MySQL Query:

DROP CONSTRAINT `ospos_items_ibfk_1`;

ALTER TABLE `ospos_items` DROP CONSTRAINT `ospos_items_ibfk_1`

ALTER TABLE `ospos_items` DROP FOREIGN KEY `ospos_items_ibfk_1`;

ALTER TABLE `ospos_items_taxes` DROP FOREIGN KEY `ospos_items_taxes_ibfk_1`;

INSERT INTO ospos_items(item_id)
SELECT (
SELECT MAX( item_id ) +1
FROM ospos_items
);

SELECT * FROM `ospos_people` WHERE p_id = (SELECT p_id from ospos_people where store_id = ‘3’);

_______________________________________________________________________________________________________________

Codeigniter  database without Primary & foreign key:

Click Here  db  to download

Sample Insert Update Delete Code

NEW CI DB Example

______________________________________________________________________________

Code of DB Example

Route File
routes.php
$route[‘default_controller’] = “manage_products”;
$route[‘manage’] = “manage_products”;
$route[‘manage_products/logout’] = “manage_products/logout”;
$route[‘product/add’] = ‘manage_products/add_product’;
$route[‘product/edit/(:any)’] = ‘manage_products/edit_product/$1’;
$route[‘product/delete/(:any)’] = ‘manage_products/delete_product/$1’;
$route[‘404_override’] = ”;
__________________________________________________________________________________________

controllers

———– index.html
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>

<p>Directory access is forbidden.</p>

</body>
</html>

———– login.php
<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Login extends CI_Controller{

function __construct(){
parent::__construct();
}

public function index(){
// Load our view to be displayed
// to the user
$this->load->view(‘login’);
}

public function process(){
// Load the model
$this->load->model(‘login_model’);
// Validate the user can login
$result = $this->login_model->validate();
// Now we verify the result
if(! $result){
// If user did not validate, then show them login page again
$this->data[‘message’] = ‘<p style=”
padding: .8em;
margin-bottom: 1em;
border: 2px solid #ddd;
background: #FFF6BF;
color: #817134;
border-color: #FFD324;
text-align: center;”>Invalid username or password.<p>’;
//$this->index(‘login’,$this->data);
$this->load->view(‘login’, $this->data);
}else{
// If user did validate,
// Send them to members area
redirect(‘manage’);
}
}
}
?>

——— manage_products.php
<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Manage_products extends CI_Controller {

public function __construct()
{
parent::__construct();

$this->load->model(‘Products_model’);
$this->load->library(‘form_validation’);
$this->check_isvalidated();
}

public function index()
{
$this->data[‘products’] = $this->Products_model->get_all();
$this->data[‘title’] = ‘Product Management’;
$this->data[‘message’] = $this->session->flashdata(‘message’);

$this->load->view(‘manage_products’, $this->data);
}

function add_product() {
$this->data[‘title’] = ‘Add Product’;

//validate form input
$this->form_validation->set_rules(‘name’, ‘Product name’, ‘required|xss_clean’);
$this->form_validation->set_rules(‘description’, ‘Description’, ‘required|xss_clean’);
$this->form_validation->set_rules(‘price’, ‘Price’, ‘trim|required|numeric’);

if ($this->form_validation->run() == true)
{
$data = array(
‘name’ => $this->input->post(‘name’),
‘description’ => $this->input->post(‘description’),
‘price’ => $this->input->post(‘price’)
);

$this->Products_model->insert_product($data);

$this->session->set_flashdata(‘message’, “<p>Product added successfully.</p>”);

redirect(base_url().’manage’);
}else{
//display the add product form
//set the flash data error message if there is one
$this->data[‘message’] = (validation_errors() ? validation_errors() : $this->session->flashdata(‘message’));

$this->data[‘name’] = array(
‘name’ => ‘name’,
‘id’ => ‘name’,
‘type’ => ‘text’,
‘style’ => ‘width:300px;’,
‘value’ => $this->form_validation->set_value(‘name’),
);
$this->data[‘description’] = array(
‘name’ => ‘description’,
‘id’ => ‘description’,
‘type’ => ‘text’,
‘cols’ => 60,
‘rows’ => 5,
‘value’ => $this->form_validation->set_value(‘description’),
);
$this->data[‘price’] = array(
‘name’ => ‘price’,
‘id’ => ‘price’,
‘type’ => ‘text’,
‘style’ => ‘width:40px;text-align: right’,
‘value’ => $this->form_validation->set_value(‘price’),
);

$this->load->view(‘add_product’, $this->data);
}
}

function edit_product($product_id) {

$product = $this->Products_model->get_product($product_id);

$this->data[‘title’] = ‘Edit Product’;

//validate form input
$this->form_validation->set_rules(‘name’, ‘Product name’, ‘required|xss_clean’);
$this->form_validation->set_rules(‘description’, ‘Description’, ‘required|xss_clean’);
$this->form_validation->set_rules(‘price’, ‘Price’, ‘trim|required|numeric’);

if (isset($_POST) && !empty($_POST))
{
$data = array(
‘name’ => $this->input->post(‘name’),
‘description’ => $this->input->post(‘description’),
‘price’ => $this->input->post(‘price’)
);

if ($this->form_validation->run() === true)
{
$this->Products_model->update_product($product_id, $data);

$this->session->set_flashdata(‘message’, “<p>Product updated successfully.</p>”);

redirect(base_url().’product/edit/’.$product_id);
}
}

$this->data[‘message’] = (validation_errors() ? validation_errors() : $this->session->flashdata(‘message’));

$this->data[‘product’] = $product;

//display the edit product form
$this->data[‘name’] = array(
‘name’ => ‘name’,
‘id’ => ‘name’,
‘type’ => ‘text’,
‘style’ => ‘width:300px;’,
‘value’ => $this->form_validation->set_value(‘name’, $product[‘name’]),
);

$this->data[‘description’] = array(
‘name’ => ‘description’,
‘id’ => ‘description’,
‘type’ => ‘text’,
‘cols’ => 60,
‘rows’ => 5,
‘value’ => $this->form_validation->set_value(‘description’, $product[‘description’]),
);

$this->data[‘price’] = array(
‘name’ => ‘price’,
‘id’ => ‘price’,
‘type’ => ‘text’,
‘style’ => ‘width:40px;text-align: right’,
‘value’ => $this->form_validation->set_value(‘price’, $product[‘price’]),
);

$this->load->view(‘edit_product’, $this->data);
}

function delete_product($product_id) {
$this->Products_model->del_product($product_id);

$this->session->set_flashdata(‘message’, ‘<p>Product were successfully deleted!</p>’);

redirect(‘manage’);
}

function logout(){
$this->session->sess_destroy();
redirect(‘login’);
}

private function check_isvalidated(){
if(! $this->session->userdata(‘validated’)){
redirect(‘login’);
}
}
}
?>

——– products.php
<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Products extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->load->model(‘Products_model’);
}

public function index()
{
$this->data[‘title’] = ‘Home — Products’;

$this->data[‘products’] = $this->Products_model->get_all();
$this->data[‘message’] = $this->session->flashdata(‘message’);

$this->load->view(‘products’, $this->data);
}
} ?>

____________________________________________________________________________________

models
——— index.html
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>

<p>Directory access is forbidden.</p>

</body>
</html>

——– login_model.php
<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);
/* Author: Jorge Torres
* Description: Login model class
*/
class Login_model extends CI_Model{
function __construct(){
parent::__construct();
}

public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post(‘username’));
$password = $this->security->xss_clean($this->input->post(‘password’));

// Prep the query
$this->db->where(‘username’, $username);
$this->db->where(‘password’, $password);

// Run the query
$query = $this->db->get(‘users’);
// Let’s check if there are any results
if($query->num_rows == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
‘userid’ => $row->userid,
‘username’ => $row->username,
‘validated’ => true
);
$this->session->set_userdata($data);
return true;
}
// If the previous process did not validate
// then return false.
return false;
}
}
?>

——- products_model.php
<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Products_model extends CI_Model {

public function __construct()
{
//$this->load->database();
}

function get_all() {
$this->db->select(‘id, name, description, price, picture’);
$query = $this->db->get(‘products’);

return $query->result_array();
}

function get_product($product_id) {
$this->db->select(‘id, name, description, price, picture’);
$this->db->where(‘id’, $product_id);
$query = $this->db->get(‘products’);

return $query->row_array();
}
public function insert_product($data)
{
$this->db->insert(‘products’, $data);

$id = $this->db->insert_id();

return (isset($id)) ? $id : FALSE;
}

public function update_product($product_id, $data)
{
$this->db->where(‘id’, $product_id);
$this->db->update(‘products’, $data);
}

public function del_product($product_id)
{
$this->db->where(‘id’, $product_id);
$this->db->delete(‘products’);
}
}
?>

_______________________________________________________________________________________
views

—— index.html
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>

<p>Directory access is forbidden.</p>

</body>
</html>

—— add_product.php
<!DOCTYPE html>
<head>
<title>HTML5 TABLE FORMATTING</title>

<style type=”text/css”>

table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}

/*** central column on page ***/
div#divContainer
{
max-width: 800px;
margin: 0 auto;
font-family: Calibri;
padding: 0.5em 1em 1em 1em;

/* rounded corners */
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#808080));
background: -moz-linear-gradient(top, #606060, #808080);

/* add box shadows */
-moz-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
}

#infoMessage p{
padding: .8em;
margin-bottom: 1em;
border: 2px solid #ddd;
background: #FFF6BF;
color: #817134;
border-color: #FFD324;
text-align: center;
}

h1 {color:#FFE47A; font-size:1.5em;}

/*** sample table to demonstrate CSS3 formatting ***/
table.formatHTML5 {
width: 100%;
border-collapse:collapse;
text-align:left;
color: #606060;
}

/*** table’s thead section, head row style ***/
table.formatHTML5 thead tr td {
background-color: White;
vertical-align:middle;
padding: 0.6em;
font-size:0.8em;
}

/*** table’s thead section, coulmns header style ***/
table.formatHTML5 thead tr th
{
padding: 0.5em;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, odd rows style ***/
table.formatHTML5 tbody tr:nth-child(odd) {
background-color: #fafafa;
}

/*** hover effect to table’s tbody odd rows ***/
table.formatHTML5 tbody tr:nth-child(odd):hover
{
cursor:pointer;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, even rows style ***/
table.formatHTML5 tbody tr:nth-child(even) {
background-color: #efefef;
}

/*** hover effect to apply to table’s tbody section, even rows ***/
table.formatHTML5 tbody tr:nth-child(even):hover
{
cursor:pointer;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, last row style ***/
table.formatHTML5 tbody tr:last-child {
border-bottom: solid 1px #404040;
}

/*** table’s tbody section, separator row pseudo-class ***/
table.formatHTML5 tbody tr.separator {
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s td element, all section ***/
table.formatHTML5 td {
vertical-align:middle;
padding: 0.5em;
}

/*** table’s tfoot section ***/
table.formatHTML5 tfoot{
text-align:center;
color:#303030;
text-shadow: 0 1px 1px rgba(255,255,255,0.3);
}
</style>

</head>
<body>

<!– CENTTERED COLUMN ON THE PAGE–>
<div id=”divContainer”>

<h1 align=”center”>Add Product !!!</h1>

<!– HTML5 TABLE FORMATTED VIA CSS3–>
<div id=”infoMessage”><?php echo $message;?></div>
<?php echo form_open(“product/add”);?>

<table class=”formatHTML5″ >

<!– TABLE HEADER–>
<thead>
<tr><td colspan=5>DISCLAIMER: Add DATA OF PRODUCT.</td></tr>
</thead>

<!– TABLE BODY: MAIN CONTENT–>
<tbody>
<tr>
<td>Name:</td>
<td><?php echo form_input($name);?></td>
</tr>

<tr>
<td>Description:</td>
<td><?php echo form_input($description);?></td>
</tr>

<tr>
<td>Price:</td>
<td><?php echo form_input($price);?></td>
</tr>

<tr>
<td></td>
<td><?php echo form_submit(‘submit’, ‘Submit’);?>
<input type=”button” name=”btnBack” id=”btnBack” value=”Back” onclick=”window.location.href='<?php echo base_url() ?>manage'” /></td>
</tr>

</tbody>

<!– TABLE FOOTER–>
<tfoot>
<tr><td colspan=”3″>Copyright &#9400 2014.</td></tr>
</tfoot>
</table>
<?php echo form_close(); ?>
</div>
</body>
</html>

——— edit_product.php

<!DOCTYPE html>
<head>
<title>HTML5 TABLE FORMATTING</title>

<style type=”text/css”>

table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}

/*** central column on page ***/
div#divContainer
{
max-width: 800px;
margin: 0 auto;
font-family: Calibri;
padding: 0.5em 1em 1em 1em;

/* rounded corners */
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#808080));
background: -moz-linear-gradient(top, #606060, #808080);

/* add box shadows */
-moz-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
}

#infoMessage p{
padding: .8em;
margin-bottom: 1em;
border: 2px solid #ddd;
background: #FFF6BF;
color: #817134;
border-color: #FFD324;
text-align: center;
}

h1 {color:#FFE47A; font-size:1.5em;}

/*** sample table to demonstrate CSS3 formatting ***/
table.formatHTML5 {
width: 100%;
border-collapse:collapse;
text-align:left;
color: #606060;
}

/*** table’s thead section, head row style ***/
table.formatHTML5 thead tr td {
background-color: White;
vertical-align:middle;
padding: 0.6em;
font-size:0.8em;
}

/*** table’s thead section, coulmns header style ***/
table.formatHTML5 thead tr th
{
padding: 0.5em;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, odd rows style ***/
table.formatHTML5 tbody tr:nth-child(odd) {
background-color: #fafafa;
}

/*** hover effect to table’s tbody odd rows ***/
table.formatHTML5 tbody tr:nth-child(odd):hover
{
cursor:pointer;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, even rows style ***/
table.formatHTML5 tbody tr:nth-child(even) {
background-color: #efefef;
}

/*** hover effect to apply to table’s tbody section, even rows ***/
table.formatHTML5 tbody tr:nth-child(even):hover
{
cursor:pointer;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, last row style ***/
table.formatHTML5 tbody tr:last-child {
border-bottom: solid 1px #404040;
}

/*** table’s tbody section, separator row pseudo-class ***/
table.formatHTML5 tbody tr.separator {
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s td element, all section ***/
table.formatHTML5 td {
vertical-align:middle;
padding: 0.5em;
}

/*** table’s tfoot section ***/
table.formatHTML5 tfoot{
text-align:center;
color:#303030;
text-shadow: 0 1px 1px rgba(255,255,255,0.3);
}
</style>

</head>
<body>

<!– CENTTERED COLUMN ON THE PAGE–>
<div id=”divContainer”>

<h1 align=”center”>Edit Product !!!</h1>
<?php $product_id = $product[‘id’]; ?>

<!– HTML5 TABLE FORMATTED VIA CSS3–>
<div id=”infoMessage”><?php echo $message;?></div>
<?php echo form_open(“product/edit/$product_id”);?>

<table class=”formatHTML5″ >

<!– TABLE HEADER–>
<thead>
<tr><td colspan=5>DISCLAIMER: Add DATA OF PRODUCT.</td></tr>
</thead>

<!– TABLE BODY: MAIN CONTENT–>
<tbody>
<tr>
<td>Name:</td>
<td><?php echo form_input($name);?></td>
</tr>

<tr>
<td>Description:</td>
<td><?php echo form_input($description);?></td>
</tr>

<tr>
<td>Price:</td>
<td><?php echo form_input($price);?></td>
</tr>

<tr>
<td></td>
<td><?php echo form_submit(‘submit’, ‘Submit’);?>
<input type=”button” name=”btnBack” id=”btnBack” value=”Back” onclick=”window.location.href='<?php echo base_url() ?>manage'” /></td>
</tr>

</tbody>

<!– TABLE FOOTER–>
<tfoot>
<tr><td colspan=”3″>Copyright &#9400 2014.</td></tr>
</tfoot>
</table>
<?php echo form_close(); ?>
</div>
</body>
</html>

——— login.php
<?php error_reporting(0); ?>

<!DOCTYPE html>
<head>
<title>HTML5 TABLE FORMATTING</title>

<style type=”text/css”>

table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}

/*** central column on page ***/
div#divContainer
{
max-width: 800px;
margin: 0 auto;
font-family: Calibri;
padding: 0.5em 1em 1em 1em;

/* rounded corners */
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#808080));
background: -moz-linear-gradient(top, #606060, #808080);

/* add box shadows */
-moz-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
}

#infoMessage p{
padding: .8em;
margin-bottom: 1em;
border: 2px solid #ddd;
background: #FFF6BF;
color: #817134;
border-color: #FFD324;
text-align: center;
}

h1 {color:#FFE47A; font-size:1.5em;}

/*** sample table to demonstrate CSS3 formatting ***/
table.formatHTML5 {
width: 100%;
border-collapse:collapse;
text-align:left;
color: #606060;
}

/*** table’s thead section, head row style ***/
table.formatHTML5 thead tr td {
background-color: White;
vertical-align:middle;
padding: 0.6em;
font-size:0.8em;
}

/*** table’s thead section, coulmns header style ***/
table.formatHTML5 thead tr th
{
padding: 0.5em;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, odd rows style ***/
table.formatHTML5 tbody tr:nth-child(odd) {
background-color: #fafafa;
}

/*** hover effect to table’s tbody odd rows ***/
table.formatHTML5 tbody tr:nth-child(odd):hover
{
cursor:pointer;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, even rows style ***/
table.formatHTML5 tbody tr:nth-child(even) {
background-color: #efefef;
}

/*** hover effect to apply to table’s tbody section, even rows ***/
table.formatHTML5 tbody tr:nth-child(even):hover
{
cursor:pointer;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, last row style ***/
table.formatHTML5 tbody tr:last-child {
border-bottom: solid 1px #404040;
}

/*** table’s tbody section, separator row pseudo-class ***/
table.formatHTML5 tbody tr.separator {
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s td element, all section ***/
table.formatHTML5 td {
vertical-align:middle;
padding: 0.5em;
}

/*** table’s tfoot section ***/
table.formatHTML5 tfoot{
text-align:center;
color:#303030;
text-shadow: 0 1px 1px rgba(255,255,255,0.3);
}
</style>

</head>
<body>

<!– CENTTERED COLUMN ON THE PAGE–>
<div id=”divContainer”>

<h1 align=”center”>User Login !!!</h1>
<?php $product_id = $product[‘id’]; ?>

<!– HTML5 TABLE FORMATTED VIA CSS3–>
<?php echo $message;?>
<?php echo form_open(“login/process”);?>

<table class=”formatHTML5″ >

<!– TABLE HEADER–>
<thead>
<tr><td colspan=5>DISCLAIMER: User Login can here.</td></tr>
</thead>

<!– TABLE BODY: MAIN CONTENT–>
<tbody>
<tr>
<td>UserName:</td>
<td><input type=’text’ name=’username’ id=’username’ size=’25’ /></td>
</tr>

<tr>
<td>Password:</td>
<td><input type=’password’ name=’password’ id=’password’ size=’25’ /></td>
</tr>

<tr>
<td></td>
<td><?php echo form_submit(‘submit’, ‘Login’);?></td>
</tr>

</tbody>

<!– TABLE FOOTER–>
<tfoot>
<tr><td colspan=”3″>Copyright &#9400 2014.</td></tr>
</tfoot>
</table>
<?php echo form_close(); ?>
</div>
</body>
</html>

——– manage_products.php
<!DOCTYPE html>
<head>
<title>HTML5 TABLE FORMATTING</title>

<style type=”text/css”>

table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}

/*** central column on page ***/
div#divContainer
{
max-width: 800px;
margin: 0 auto;
font-family: Calibri;
padding: 0.5em 1em 1em 1em;

/* rounded corners */
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;

/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#808080));
background: -moz-linear-gradient(top, #606060, #808080);

/* add box shadows */
-moz-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
box-shadow: 5px 5px 10px rgba(0,0,0,0.3);
}

#infoMessage p{
padding: .8em;
margin-bottom: 1em;
border: 2px solid #ddd;
background: #FFF6BF;
color: #817134;
border-color: #FFD324;
text-align: center;
}

h1 {color:#FFE47A; font-size:1.5em;}

/*** sample table to demonstrate CSS3 formatting ***/
table.formatHTML5 {
width: 100%;
border-collapse:collapse;
text-align:left;
color: #606060;
}

/*** table’s thead section, head row style ***/
table.formatHTML5 thead tr td {
background-color: White;
vertical-align:middle;
padding: 0.6em;
font-size:0.8em;
}

/*** table’s thead section, coulmns header style ***/
table.formatHTML5 thead tr th
{
padding: 0.5em;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, odd rows style ***/
table.formatHTML5 tbody tr:nth-child(odd) {
background-color: #fafafa;
}

/*** hover effect to table’s tbody odd rows ***/
table.formatHTML5 tbody tr:nth-child(odd):hover
{
cursor:pointer;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, even rows style ***/
table.formatHTML5 tbody tr:nth-child(even) {
background-color: #efefef;
}

/*** hover effect to apply to table’s tbody section, even rows ***/
table.formatHTML5 tbody tr:nth-child(even):hover
{
cursor:pointer;
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s tbody section, last row style ***/
table.formatHTML5 tbody tr:last-child {
border-bottom: solid 1px #404040;
}

/*** table’s tbody section, separator row pseudo-class ***/
table.formatHTML5 tbody tr.separator {
/* add gradient */
background-color: #808080;
background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));
background: -moz-linear-gradient(top, #606060, #909090);
color: #dadada;
}

/*** table’s td element, all section ***/
table.formatHTML5 td {
vertical-align:middle;
padding: 0.5em;
}

/*** table’s tfoot section ***/
table.formatHTML5 tfoot{
text-align:center;
color:#303030;
text-shadow: 0 1px 1px rgba(255,255,255,0.3);
}
</style>

</head>
<body>

<!– CENTTERED COLUMN ON THE PAGE–>
<div id=”divContainer”>

<h1 align=”center”>Welcome to Admin !!!</h1>

<!– HTML5 TABLE FORMATTED VIA CSS3–>
<table class=”formatHTML5″ >

<!– TABLE HEADER–>
<thead>
<tr><td colspan=5>DISCLAIMER: ALL DATA OF PRODUCT. <input name=”New” type=”button” value=”Add New” onclick=”window.location=’product/add'” />
<input name=”Logout” type=”button” value=”Logout” onclick=”window.location=’manage_products/logout'” /></td></tr>
<tr>
<th>Product</th><th>Inflation Rate</th><th>Note</th><th></th><th></th>
</tr>
</thead>

<!– TABLE BODY: MAIN CONTENT–>
<tbody>

<?php
foreach ($products as $product){
$product_id = $product[‘id’];
?>
<tr>
<td><?php echo $product[‘name’] ?></td>
<td><?php echo $product[‘description’] ?></td>
<td><?php echo $product[‘price’] ?></td>
<td><a href=’product/edit/<?php echo $product_id ?>’>Edit</a></td>
<td>
<?php
echo anchor(‘product/delete/’.$product_id, ‘Delete’, array(‘onClick’ => “return confirm(‘Are you sure you want to delete?’)”));
?>
</td>
</tr>
<?php
}
?>

</tbody>

<!– TABLE FOOTER–>
<tfoot>
<tr><td colspan=”3″>Copyright &#9400 2014.</td></tr>
</tfoot>
</table>
</div>
</body>
</html>

——— products.php
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title><?php echo $title; ?></title>
<style type=”text/css”>
#infoMessage p{
padding: .8em;
margin-bottom: 1em;
border: 2px solid #ddd;
background: #FFF6BF;
color: #817134;
border-color: #FFD324;
}
</style>
</head>
<body>
<div align=”center”>
<h1 align=”center”>Products (<a href=”<?php echo base_url().’manage’ ?>”>Manage</a>)</h1>
<div id=”infoMessage”><?php echo $message;?></div>
<table border=”0″ cellpadding=”2px” width=”600px”>
<?php
foreach ($products as $product){
$id = $product[‘id’];
$name = $product[‘name’];
$description = $product[‘description’];
$price = $product[‘price’];
?>
<tr>
<td><b><?php echo $name; ?></b><br />
<?php echo $description; ?><br />
Price:<big style=”color:green”>
$<?php echo $price; ?></big><br /><br />
<?php
echo form_hidden(‘id’, $id);
echo form_hidden(‘name’, $name);
echo form_hidden(‘price’, $price);
?>
</td>
</tr>
<tr><td colspan=”2″><hr size=”1″ /></td>
<?php } ?>
</table>
</div>
</body>
</html>

___________________________________________________________________________________

DB.SQL

CREATE TABLE IF NOT EXISTS `products` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) COLLATE latin1_general_ci NOT NULL,
`description` varchar(255) COLLATE latin1_general_ci NOT NULL,
`price` float NOT NULL,
`picture` varchar(80) COLLATE latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=14 ;


— Dumping data for table `products`

INSERT INTO `products` (`id`, `name`, `description`, `price`, `picture`) VALUES
(2, ‘IBM CDROM Drive’, ‘IBM CDROM Drive.’, 19, ‘images/cdrom-drive.jpg’),
(3, ‘Laptop Charger’, ‘Dell Laptop Charger with 6 months warranty’, 50, ‘images/charger.jpg’),
(4, ‘Seagate Hard Drive’, ’80 GB Seagate Hard Drive in 10 months warranty.’, 40, ‘images/hard-drive.jpg’),
(5, ‘Atech Mouse.’, ‘Black colored laser mouse. No warranty’, 3, ‘images/mouse.jpg’),
(6, ‘Nokia 58001’, ‘58001 XpressMusic is a mobile device with 3.2″ widescreen display brings photos, video clips and web content to life’, 1299, ‘images/mobile.jpg’);

— ——————————————————–


— Table structure for table `users`

CREATE TABLE IF NOT EXISTS `users` (
`userid` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


— Dumping data for table `users`

INSERT INTO `users` (`userid`, `username`, `password`) VALUES
(1, ‘admin’, ‘admin’),
(2, ‘admin1’, ‘admin1’);

CI DB example

=============================== 14-2-14 ====================================

Route File

routes.php

$route[‘default_controller’] = “manage_products”;

$route[‘manage’] = “manage_products”;

$route[‘manage_products/logout’] = “manage_products/logout”;

$route[‘product/add’] = ‘manage_products/add_product’;

$route[‘product/edit/(:any)’] = ‘manage_products/edit_product/$1’;

$route[‘product/delete/(:any)’] = ‘manage_products/delete_product/$1’;

$route[‘404_override’] = ”;

__________________________________________________________________________________________

controllers

———– index.html

<html>

<head>

<title>403 Forbidden</title>

</head>

<body>

<p>Directory access is forbidden.</p>

</body>

</html>

———– login.php

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Login extends CI_Controller{

function __construct(){

parent::__construct();

}

public function index(){

// Load our view to be displayed

// to the user

$this->load->view(‘login’);

}

public function process(){

// Load the model

$this->load->model(‘login_model’);

// Validate the user can login

$result = $this->login_model->validate();

// Now we verify the result

if(! $result){

// If user did not validate, then show them login page again

$this->data[‘message’] = ‘<p style=”

padding: .8em;

margin-bottom: 1em;

border: 2px solid #ddd;

background: #FFF6BF;

color: #817134;

border-color: #FFD324;

text-align: center;”>Invalid username or password.<p>’;

//$this->index(‘login’,$this->data);

$this->load->view(‘login’, $this->data);

}else{

// If user did validate,

// Send them to members area

redirect(‘manage’);

}

}

}

?>

——— manage_product.php

<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Manage_products extends CI_Controller {

public function __construct()

{

parent::__construct();

$this->load->model(‘Products_model’);

$this->load->library(‘form_validation’);

$this->check_isvalidated();

$this->load->library(“pagination”);

$this->load->helper(“url”);

}

public function index()

{

$this->data[‘title’] = ‘Product Management’;

$this->data[‘message’] = $this->session->flashdata(‘message’);

$config = array();

//$config[“base_url”] = base_url() . “welcome/welcome_message”;

$config[‘base_url’] = base_url(‘Manage_products/index/’);

$config[“total_rows”] = $this->Products_model->record_count();

$config[“per_page”] = 5;

$config[“uri_segment”] = 3;

$this->pagination->initialize($config);

$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

$this->data[‘products’] = $this->Products_model->get_all($config[“per_page”], $page);

$this->data[“links”] = $this->pagination->create_links();

$this->load->view(‘manage_products’, $this->data);

}

function add_product() {

$this->data[‘title’] = ‘Add Product’;

// Category Dropdown

$categories = array(” => ‘Select Category’);

foreach($this->Products_model->get_all_category() as $row)

{

$categories[$row[‘id’]] = $row[‘name’];

}

$this->data[‘categories’] = $categories;

$this->data[‘selected_category’] =  $this->input->post(‘category_id’);

// Supplier Dropdown

$this->data[‘suppliers’] = array(” => ‘Select Supplier’);

$this->data[‘selected_supplier’] =  $this->input->post(‘supplier_id’);

//validate form input

$this->form_validation->set_rules(‘name’, ‘Product name’, ‘required|xss_clean’);

$this->form_validation->set_rules(‘category_id’, ‘Category’, ‘required|xss_clean’);

$this->form_validation->set_rules(‘supplier_id’, ‘Supplier’, ‘required|xss_clean’);

$this->form_validation->set_rules(‘description’, ‘Description’, ‘required|xss_clean’);

$this->form_validation->set_rules(‘price’, ‘Price’, ‘trim|required|numeric’);

if ($this->form_validation->run() == true)

{

$data = array(

‘name’                                       => $this->input->post(‘name’),

‘description’                  => $this->input->post(‘description’),

‘price’                           => $this->input->post(‘price’),

‘category_id’                 => $this->input->post(‘category_id’),

‘supplier_id’                  => $this->input->post(‘supplier_id’),

);

$this->Products_model->insert_product($data);

$this->session->set_flashdata(‘message’, “<p>Product added successfully.</p>”);

redirect(base_url().’manage’);

}else{

//display the add product form

//set the flash data error message if there is one

$this->data[‘message’] = (validation_errors() ? validation_errors() : $this->session->flashdata(‘message’));

$this->data[‘name’] = array(

‘name’  => ‘name’,

‘id’        => ‘name’,

‘type’    => ‘text’,

‘style’                => ‘width:300px;’,

‘value’   => $this->form_validation->set_value(‘name’),

);

$this->data[‘description’] = array(

‘name’  => ‘description’,

‘id’        => ‘description’,

‘type’    => ‘text’,

‘cols’                 =>        60,

‘rows’               =>        5,

‘value’   => $this->form_validation->set_value(‘description’),

);

$this->data[‘price’] = array(

‘name’  => ‘price’,

‘id’        => ‘price’,

‘type’    => ‘text’,

‘style’                => ‘width:40px;text-align: right’,

‘value’   => $this->form_validation->set_value(‘price’),

);

$this->load->view(‘add_product’, $this->data);

}

}

function edit_product($product_id) {

$product = $this->Products_model->get_product($product_id);

$this->data[‘title’] = ‘Edit Product’;

//validate form input

$this->form_validation->set_rules(‘name’, ‘Product name’, ‘required|xss_clean’);

$this->form_validation->set_rules(‘description’, ‘Description’, ‘required|xss_clean’);

$this->form_validation->set_rules(‘price’, ‘Price’, ‘trim|required|numeric’);

if (isset($_POST) && !empty($_POST))

{

$data = array(

‘name’                                                   => $this->input->post(‘name’),

‘description’                              => $this->input->post(‘description’),

‘price’                                       => $this->input->post(‘price’)

);

if ($this->form_validation->run() === true)

{

$this->Products_model->update_product($product_id, $data);

$this->session->set_flashdata(‘message’, “<p>Product updated successfully.</p>”);

redirect(base_url().’product/edit/’.$product_id);

}

}

$this->data[‘message’] = (validation_errors() ? validation_errors() : $this->session->flashdata(‘message’));

$this->data[‘product’] = $product;

//display the edit product form

$this->data[‘name’] = array(

‘name’  => ‘name’,

‘id’        => ‘name’,

‘type’    => ‘text’,

‘style’                => ‘width:300px;’,

‘value’   => $this->form_validation->set_value(‘name’, $product[‘name’]),

);

$this->data[‘description’] = array(

‘name’  => ‘description’,

‘id’        => ‘description’,

‘type’    => ‘text’,

‘cols’                 =>        60,

‘rows’               =>        5,

‘value’   => $this->form_validation->set_value(‘description’, $product[‘description’]),

);

$this->data[‘price’] = array(

‘name’  => ‘price’,

‘id’        => ‘price’,

‘type’    => ‘text’,

‘style’                => ‘width:40px;text-align: right’,

‘value’   => $this->form_validation->set_value(‘price’, $product[‘price’]),

);

$this->load->view(‘edit_product’, $this->data);

}

function delete_product($product_id) {

$this->Products_model->del_product($product_id);

$this->session->set_flashdata(‘message’, ‘<p>Product were successfully deleted!</p>’);

redirect(‘manage’);

}

function logout(){

$this->session->sess_destroy();

redirect(‘login’);

}

private function check_isvalidated(){

if(! $this->session->userdata(‘validated’)){

redirect(‘login’);

}

}

function search()

{

$this->data[‘products’] = $this->Products_model->search($this->input->post(‘search’));

$this->data[‘search’] = $this->input->post(‘search’);

//print_r($this->data[‘products’]);

//die(‘Here’);;

$this->load->view(‘manage_products’, $this->data);

}

}

——– products.php

<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Products extends CI_Controller {

public function __construct()

{

parent::__construct();

$this->load->model(‘Products_model’);

}

public function index()

{

$this->data[‘title’] = ‘Home — Products’;

$this->data[‘products’] = $this->Products_model->get_all();

$this->data[‘message’] = $this->session->flashdata(‘message’);

$this->load->view(‘products’, $this->data);

}

}

Models

————  index.html

<html>

<head>

<title>403 Forbidden</title>

</head>

<body>

<p>Directory access is forbidden.</p>

</body>

</html>

———- login_model.php

<?php if ( ! defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

/* Author: Jorge Torres

* Description: Login model class

*/

class Login_model extends CI_Model{

function __construct(){

parent::__construct();

}

public function validate(){

// grab user input

$username = $this->security->xss_clean($this->input->post(‘username’));

$password = $this->security->xss_clean($this->input->post(‘password’));

// Prep the query

$this->db->where(‘username’, $username);

$this->db->where(‘password’, $password);

// Run the query

$query = $this->db->get(‘users’);

// Let’s check if there are any results

if($query->num_rows == 1)

{

// If there is a user, then create session data

$row = $query->row();

$data = array(

‘userid’ => $row->userid,

‘username’ => $row->username,

‘validated’ => true

);

$this->session->set_userdata($data);

return true;

}

// If the previous process did not validate

// then return false.

return false;

}

}

?>

——— products_model.php

<?php if (!defined(‘BASEPATH’)) exit(‘No direct script access allowed’);

class Products_model extends CI_Model {

public function __construct()

{

//$this->load->database();

}

function search($search)

{

$this->db->select(‘id, name, description, price, supplier_id’);

$this->db->where(“(`name` LIKE ‘%”.$this->db->escape_like_str($search).”%’)”);

$query = $this->db->get(‘products’);

return $query->result_array();

}

public function record_count() {

return $this->db->count_all(“products”);

}

public function fetch_products($limit, $start) {

$this->db->limit($limit, $start);

$query = $this->db->get(“products”);

if ($query->num_rows() > 0) {

foreach ($query->result() as $row) {

$data[] = $row;

}

return $data;

}

return false;

}

function get_all_category() {

$this->db->select(‘id, name’);

$query = $this->db->get(‘category’);

return $query->result_array();

}

function get_all($limit, $start) {

$this->db->limit($limit, $start);

$this->db->select(‘id, name, description, price, supplier_id’);

$query = $this->db->get(‘products’);

return $query->result_array();

}

function get_product($product_id) {

$this->db->select(‘id, name, description, price, supplier_id’);

$this->db->where(‘id’, $product_id);

$query = $this->db->get(‘products’);

return $query->row_array();

}

public function insert_product($data)

{

$this->db->insert(‘products’, $data);

$id = $this->db->insert_id();

return (isset($id)) ? $id : FALSE;

}

public function update_product($product_id, $data)

{

$this->db->where(‘id’, $product_id);

$this->db->update(‘products’, $data);

}

public function del_product($product_id)

{

$this->db->where(‘id’, $product_id);

$this->db->delete(‘products’);

}

}

Views

———- index.html

<html>

<head>

<title>403 Forbidden</title>

</head>

<body>

<p>Directory access is forbidden.</p>

</body>

</html>

———–   add_product.php

<!DOCTYPE html>

<head>

<title>Add Product</title>

<style type=”text/css”>

table, td, th

{

border:1px solid green;

}

th

{

background-color:green;

color:white;

}

/*** central column on page ***/

div#divContainer

{

max-width: 800px;

margin: 0 auto;

font-family: Calibri;

padding: 0.5em 1em 1em 1em;

/* rounded corners */

-moz-border-radius: 10px;

-webkit-border-radius: 10px;

border-radius: 10px;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#808080));

background: -moz-linear-gradient(top, #606060, #808080);

/* add box shadows */

-moz-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

}

#infoMessage p{

padding: .8em;

margin-bottom: 1em;

border: 2px solid #ddd;

background: #FFF6BF;

color: #817134;

border-color: #FFD324;

text-align: center;

}

h1 {color:#FFE47A; font-size:1.5em;}

/*** sample table to demonstrate CSS3 formatting ***/

table.formatHTML5 {

width: 100%;

border-collapse:collapse;

text-align:left;

color: #606060;

}

/*** table’s thead section, head row style ***/

table.formatHTML5 thead tr td  {

background-color: White;

vertical-align:middle;

padding: 0.6em;

font-size:0.8em;

}

/*** table’s thead section, coulmns header style ***/

table.formatHTML5 thead tr th

{

padding: 0.5em;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, odd rows style ***/

table.formatHTML5 tbody tr:nth-child(odd) {

background-color: #fafafa;

}

/*** hover effect to table’s tbody odd rows ***/

table.formatHTML5 tbody tr:nth-child(odd):hover

{

cursor:pointer;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, even rows style ***/

table.formatHTML5 tbody tr:nth-child(even) {

background-color: #efefef;

}

/*** hover effect to apply to table’s tbody section, even rows ***/

table.formatHTML5 tbody tr:nth-child(even):hover

{

cursor:pointer;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, last row style ***/

table.formatHTML5 tbody tr:last-child {

border-bottom: solid 1px #404040;

}

/*** table’s tbody section, separator row pseudo-class ***/

table.formatHTML5 tbody tr.separator {

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s td element, all section ***/

table.formatHTML5 td {

vertical-align:middle;

padding: 0.5em;

}

/*** table’s tfoot section ***/

table.formatHTML5 tfoot{

text-align:center;

color:#303030;

text-shadow: 0 1px 1px rgba(255,255,255,0.3);

}

</style>

</head>

<body>

<!– CENTTERED COLUMN ON THE PAGE–>

<div id=”divContainer”>

<h1 align=”center”>Add Product !!!</h1>

<!– HTML5 TABLE FORMATTED VIA CSS3–>

<div id=”infoMessage”><?php echo $message;?></div>

<?php echo form_open(“product/add”);?>

<table class=”formatHTML5″ >

<!– TABLE HEADER–>

<thead>

<tr><td colspan=5>DISCLAIMER: Add DATA OF PRODUCT.</td></tr>

</thead>

<!– TABLE BODY: MAIN CONTENT–>

<tbody>

<tr>

<td>Name:</td>

<td><?php echo form_input($name);?></td>

</tr>

<tr>

<td>Category:</td>

<td><?php echo form_dropdown(‘category_id’, $categories, $selected_category);?></td>

</tr>

<tr>

<td>Supplier:</td>

<td><?php echo form_dropdown(‘supplier_id’, $suppliers, $selected_supplier);?></td>

</tr>

<tr>

<td>Description:</td>

<td><?php echo form_input($description);?></td>

</tr>

<tr>

<td>Price:</td>

<td><?php echo form_input($price);?></td>

</tr>

<tr>

<td></td>

<td><?php echo form_submit(‘submit’, ‘Submit’);?>

<input type=”button” name=”btnBack” id=”btnBack” value=”Back” onclick=”window.location.href='<?php echo base_url() ?>manage'” /></td>

</tr>

</tbody>

<!– TABLE FOOTER–>

<tfoot>

<tr><td colspan=”3″>Copyright &#9400 2014.</td></tr>

</tfoot>

</table>

<?php echo form_close(); ?>

</div>

</body>

</html>

——— edit_product.php

<!DOCTYPE html>

<head>

<title>HTML5 TABLE FORMATTING</title>

<style type=”text/css”>

table, td, th

{

border:1px solid green;

}

th

{

background-color:green;

color:white;

}

/*** central column on page ***/

div#divContainer

{

max-width: 800px;

margin: 0 auto;

font-family: Calibri;

padding: 0.5em 1em 1em 1em;

/* rounded corners */

-moz-border-radius: 10px;

-webkit-border-radius: 10px;

border-radius: 10px;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#808080));

background: -moz-linear-gradient(top, #606060, #808080);

/* add box shadows */

-moz-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

}

#infoMessage p{

padding: .8em;

margin-bottom: 1em;

border: 2px solid #ddd;

background: #FFF6BF;

color: #817134;

border-color: #FFD324;

text-align: center;

}

h1 {color:#FFE47A; font-size:1.5em;}

/*** sample table to demonstrate CSS3 formatting ***/

table.formatHTML5 {

width: 100%;

border-collapse:collapse;

text-align:left;

color: #606060;

}

/*** table’s thead section, head row style ***/

table.formatHTML5 thead tr td  {

background-color: White;

vertical-align:middle;

padding: 0.6em;

font-size:0.8em;

}

/*** table’s thead section, coulmns header style ***/

table.formatHTML5 thead tr th

{

padding: 0.5em;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, odd rows style ***/

table.formatHTML5 tbody tr:nth-child(odd) {

background-color: #fafafa;

}

/*** hover effect to table’s tbody odd rows ***/

table.formatHTML5 tbody tr:nth-child(odd):hover

{

cursor:pointer;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, even rows style ***/

table.formatHTML5 tbody tr:nth-child(even) {

background-color: #efefef;

}

/*** hover effect to apply to table’s tbody section, even rows ***/

table.formatHTML5 tbody tr:nth-child(even):hover

{

cursor:pointer;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, last row style ***/

table.formatHTML5 tbody tr:last-child {

border-bottom: solid 1px #404040;

}

/*** table’s tbody section, separator row pseudo-class ***/

table.formatHTML5 tbody tr.separator {

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s td element, all section ***/

table.formatHTML5 td {

vertical-align:middle;

padding: 0.5em;

}

/*** table’s tfoot section ***/

table.formatHTML5 tfoot{

text-align:center;

color:#303030;

text-shadow: 0 1px 1px rgba(255,255,255,0.3);

}

</style>

</head>

<body>

<!– CENTTERED COLUMN ON THE PAGE–>

<div id=”divContainer”>

<h1 align=”center”>Edit Product !!!</h1>

<?php $product_id = $product[‘id’]; ?>

<!– HTML5 TABLE FORMATTED VIA CSS3–>

<div id=”infoMessage”><?php echo $message;?></div>

<?php echo form_open(“product/edit/$product_id”);?>

<table class=”formatHTML5″ >

<!– TABLE HEADER–>

<thead>

<tr><td colspan=5>DISCLAIMER: Add DATA OF PRODUCT.</td></tr>

</thead>

<!– TABLE BODY: MAIN CONTENT–>

<tbody>

<tr>

<td>Name:</td>

<td><?php echo form_input($name);?></td>

</tr>

<tr>

<td>Description:</td>

<td><?php echo form_input($description);?></td>

</tr>

<tr>

<td>Price:</td>

<td><?php echo form_input($price);?></td>

</tr>

<tr>

<td></td>

<td><?php echo form_submit(‘submit’, ‘Submit’);?>

<input type=”button” name=”btnBack” id=”btnBack” value=”Back” onclick=”window.location.href='<?php echo base_url() ?>manage'” /></td>

</tr>

</tbody>

<!– TABLE FOOTER–>

<tfoot>

<tr><td colspan=”3″>Copyright &#9400 2014.</td></tr>

</tfoot>

</table>

<?php echo form_close(); ?>

</div>

</body>

</html>

———–  login.php

<?php error_reporting(0); ?>

<!DOCTYPE html>

<head>

<title>HTML5 TABLE FORMATTING</title>

<style type=”text/css”>

table, td, th

{

border:1px solid green;

}

th

{

background-color:green;

color:white;

}

/*** central column on page ***/

div#divContainer

{

max-width: 800px;

margin: 0 auto;

font-family: Calibri;

padding: 0.5em 1em 1em 1em;

/* rounded corners */

-moz-border-radius: 10px;

-webkit-border-radius: 10px;

border-radius: 10px;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#808080));

background: -moz-linear-gradient(top, #606060, #808080);

/* add box shadows */

-moz-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

}

#infoMessage p{

padding: .8em;

margin-bottom: 1em;

border: 2px solid #ddd;

background: #FFF6BF;

color: #817134;

border-color: #FFD324;

text-align: center;

}

h1 {color:#FFE47A; font-size:1.5em;}

/*** sample table to demonstrate CSS3 formatting ***/

table.formatHTML5 {

width: 100%;

border-collapse:collapse;

text-align:left;

color: #606060;

}

/*** table’s thead section, head row style ***/

table.formatHTML5 thead tr td  {

background-color: White;

vertical-align:middle;

padding: 0.6em;

font-size:0.8em;

}

/*** table’s thead section, coulmns header style ***/

table.formatHTML5 thead tr th

{

padding: 0.5em;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, odd rows style ***/

table.formatHTML5 tbody tr:nth-child(odd) {

background-color: #fafafa;

}

/*** hover effect to table’s tbody odd rows ***/

table.formatHTML5 tbody tr:nth-child(odd):hover

{

cursor:pointer;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, even rows style ***/

table.formatHTML5 tbody tr:nth-child(even) {

background-color: #efefef;

}

/*** hover effect to apply to table’s tbody section, even rows ***/

table.formatHTML5 tbody tr:nth-child(even):hover

{

cursor:pointer;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, last row style ***/

table.formatHTML5 tbody tr:last-child {

border-bottom: solid 1px #404040;

}

/*** table’s tbody section, separator row pseudo-class ***/

table.formatHTML5 tbody tr.separator {

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s td element, all section ***/

table.formatHTML5 td {

vertical-align:middle;

padding: 0.5em;

}

/*** table’s tfoot section ***/

table.formatHTML5 tfoot{

text-align:center;

color:#303030;

text-shadow: 0 1px 1px rgba(255,255,255,0.3);

}

</style>

</head>

<body>

<!– CENTTERED COLUMN ON THE PAGE–>

<div id=”divContainer”>

<h1 align=”center”>User Login !!!</h1>

<?php $product_id = $product[‘id’]; ?>

<!– HTML5 TABLE FORMATTED VIA CSS3–>

<?php echo $message;?>

<?php echo form_open(“login/process”);?>

<table >

<!– TABLE HEADER–>

<thead>

<tr><td colspan=5>DISCLAIMER: User Login can here.</td></tr>

</thead>

<!– TABLE BODY: MAIN CONTENT–>

<tbody>

<tr>

<td>UserName:</td>

<td><input type=’text’ name=’username’ id=’username’ size=’25’ /></td>

</tr>

<tr>

<td>Password:</td>

<td><input type=’password’ name=’password’ id=’password’ size=’25’ /></td>

</tr>

<tr>

<td></td>

<td><?php echo form_submit(‘submit’, ‘Login’);?></td>

</tr>

</tbody>

<!– TABLE FOOTER–>

<tfoot>

<tr><td colspan=”3″>Copyright &#9400 2014.</td></tr>

</tfoot>

</table>

<?php echo form_close(); ?>

</div>

</body>

</html>

——— manage_products.php

<?php error_reporting(0); ?>

<!DOCTYPE html>

<head>

<title>Product Management</title>

<style type=”text/css”>

table, td, th

{

border:1px solid green;

}

th

{

background-color:green;

color:white;

}

/*** central column on page ***/

div#divContainer

{

max-width: 800px;

margin: 0 auto;

font-family: Calibri;

padding: 0.5em 1em 1em 1em;

/* rounded corners */

-moz-border-radius: 10px;

-webkit-border-radius: 10px;

border-radius: 10px;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#808080));

background: -moz-linear-gradient(top, #606060, #808080);

/* add box shadows */

-moz-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

box-shadow: 5px 5px 10px rgba(0,0,0,0.3);

}

#infoMessage p{

padding: .8em;

margin-bottom: 1em;

border: 2px solid #ddd;

background: #FFF6BF;

color: #817134;

border-color: #FFD324;

text-align: center;

}

h1 {color:#FFE47A; font-size:1.5em;}

/*** sample table to demonstrate CSS3 formatting ***/

table.formatHTML5 {

width: 100%;

border-collapse:collapse;

text-align:left;

color: #606060;

}

/*** table’s thead section, head row style ***/

table.formatHTML5 thead tr td  {

background-color: White;

vertical-align:middle;

padding: 0.6em;

font-size:0.8em;

}

/*** table’s thead section, coulmns header style ***/

table.formatHTML5 thead tr th

{

padding: 0.5em;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, odd rows style ***/

table.formatHTML5 tbody tr:nth-child(odd) {

background-color: #fafafa;

}

/*** hover effect to table’s tbody odd rows ***/

table.formatHTML5 tbody tr:nth-child(odd):hover

{

cursor:pointer;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, even rows style ***/

table.formatHTML5 tbody tr:nth-child(even) {

background-color: #efefef;

}

/*** hover effect to apply to table’s tbody section, even rows ***/

table.formatHTML5 tbody tr:nth-child(even):hover

{

cursor:pointer;

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s tbody section, last row style ***/

table.formatHTML5 tbody tr:last-child {

border-bottom: solid 1px #404040;

}

/*** table’s tbody section, separator row pseudo-class ***/

table.formatHTML5 tbody tr.separator {

/* add gradient */

background-color: #808080;

background: -webkit-gradient(linear, left top, left bottom, from(#606060), to(#909090));

background: -moz-linear-gradient(top, #606060, #909090);

color: #dadada;

}

/*** table’s td element, all section ***/

table.formatHTML5 td {

vertical-align:middle;

padding: 0.5em;

}

/*** table’s tfoot section ***/

table.formatHTML5 tfoot{

text-align:center;

color:#303030;

text-shadow: 0 1px 1px rgba(255,255,255,0.3);

}

</style>

</head>

<body>

<!– CENTTERED COLUMN ON THE PAGE–>

<div id=”divContainer”>

<h1 align=”center”>Welcome to Admin !!!</h1>

<!– HTML5 TABLE FORMATTED VIA CSS3–>

<table class=”formatHTML5″ >

<!– TABLE HEADER–>

<thead>

<tr><td colspan=5>DISCLAIMER: ALL DATA OF PRODUCT. <input name=”New” type=”button” value=”Add New” onclick=”window.location=’http://localhost/CI_add_edit_delete/product/add'&#8221; />

<input name=”Logout” type=”button” value=”Logout” onclick=”window.location=’manage_products/logout'” />

<?php

echo form_open(“manage_products/search”);

echo form_input(‘search’,$search);

echo form_submit(‘submit’, ‘Submit’);

echo form_close();

?>

</td></tr>

<tr>

<th>Product</th><th>Inflation Rate</th><th>Note</th><th></th><th></th>

</tr>

</thead>

<!– TABLE BODY: MAIN CONTENT–>

<tbody>

<?php

if(empty($products))

{

echo ‘<tr><td colspan=5 align=”center”>No Record Found</td></tr>’;

}

foreach ($products as $product){

$product_id = $product[‘id’];

?>

<tr>

<td><?php echo $product[‘name’] ?></td>

<td><?php echo $product[‘description’] ?></td>

<td><?php echo $product[‘price’] ?></td>

<td><a href=’http://localhost/CI_add_edit_delete/product/edit/&lt;?php echo $product_id ?>’>Edit</a></td>

<td>

<?php

echo anchor(‘product/delete/’.$product_id, ‘Delete’, array(‘onClick’ => “return confirm(‘Are you sure you want to delete?’)”));

?>

</td>

</tr>

<?php

}

?>

</tbody>

<!– TABLE FOOTER–>

<tfoot>

<tr><td colspan=”3″>Copyright &#9400 2014.</td></tr>

</tfoot>

</table>

<p><?php echo $links; ?></p>

</div>

</body>

</html>

———- products.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />

<title><?php echo $title; ?></title>

<style type=”text/css”>

#infoMessage p{

padding: .8em;

margin-bottom: 1em;

border: 2px solid #ddd;

background: #FFF6BF;

color: #817134;

border-color: #FFD324;

}

</style>

</head>

<body>

<div align=”center”>

<h1 align=”center”>Products (<a href=”<?php echo base_url().’manage’ ?>”>Manage</a>)</h1>

<div id=”infoMessage”><?php echo $message;?></div>

<table border=”0″ cellpadding=”2px” width=”600px”>

<?php

foreach ($products as $product){

$id = $product[‘id’];

$name = $product[‘name’];

$description = $product[‘description’];

$price = $product[‘price’];

?>

<tr>

<td><b><?php echo $name; ?></b><br />

<?php echo $description; ?><br />

Price:<big style=”color:green”>

$<?php echo $price; ?></big><br /><br />

<?php

echo form_hidden(‘id’, $id);

echo form_hidden(‘name’, $name);

echo form_hidden(‘price’, $price);

?>

</td>

</tr>

<tr><td colspan=”2″><hr size=”1″ /></td>

<?php } ?>

</table>

</div>

</body>

</html>

——– .htaccess

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /CI_add_edit_delete/

#Removes access to the system folder by users.

#Additionally this will allow you to create a System.php controller,

#previously this would not have been possible.

#’system’ can be replaced if you have renamed your system folder.

RewriteCond %{REQUEST_URI} ^system.*

RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn’t in the system folder

#This snippet prevents user access to the application folder

#Submitted by: Fabdrol

#Rename ‘application’ to your applications folder name.

RewriteCond %{REQUEST_URI} ^application.*

RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,

#such as an image or css document, if this isn’t true it sends the

#request to index.php

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>

# If we don’t have mod_rewrite installed, all 404’s

# can be sent to index.php, and everything works as normal.

# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php

</IfModule>

_______________________________________________ SQL ___________________________________________________

— phpMyAdmin SQL Dump

— version 3.4.5

http://www.phpmyadmin.net

— Host: localhost

— Generation Time: Feb 14, 2014 at 03:13 AM

— Server version: 5.5.8

— PHP Version: 5.3.8

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;

SET time_zone = “+00:00”;

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

— Database: `codeigniter`

— ——————————————————–

— Table structure for table `category`

CREATE TABLE IF NOT EXISTS `category` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`name` varchar(100) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

— Dumping data for table `category`

INSERT INTO `category` (`id`, `name`) VALUES

(1, ‘Cat 1’),

(2, ‘Cat 2’),

(3, ‘Cat 3’),

(4, ‘Cat 4’),

(5, ‘Cat 5’);

— ——————————————————–

— Table structure for table `products`

CREATE TABLE IF NOT EXISTS `products` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`name` varchar(20) COLLATE latin1_general_ci NOT NULL,

`description` varchar(255) COLLATE latin1_general_ci NOT NULL,

`price` float NOT NULL,

`supplier_id` int(11) NOT NULL,

`category_id` int(11) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=24 ;

— Dumping data for table `products`

INSERT INTO `products` (`id`, `name`, `description`, `price`, `supplier_id`, `category_id`) VALUES

(14, ‘IBM CDROM Drive’, ‘IBM CDROM Drive.’, 11, 1, 0),

(20, ‘sss’, ‘ssssss’, 22, 2, 0),

(3, ‘Laptop Charger’, ‘Dell Laptop Charger with 6 months warranty’, 50, 4, 0),

(4, ‘Seagate Hard Drive’, ’80 GB Seagate Hard Drive in 10 months warranty.’, 40, 5, 0),

(17, ‘Atech Mouse.11’, ‘SDD1’, 111, 1, 0),

(21, ‘JKK’, ‘JJJ’, 77, 2, 0),

(18, ‘SSS’, ‘SSS’, 33, 3, 0),

(19, ‘AAA’, ‘AAA’, 22, 4, 0),

(22, ‘Nokia 58001’, ‘SDD’, 11, 4, 0),

(23, ‘AAA’, ‘AAA’, 222, 0, 2);

— ——————————————————–

— Table structure for table `supplier`

CREATE TABLE IF NOT EXISTS `supplier` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`name` varchar(100) NOT NULL,

`category_id` int(11) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

— Dumping data for table `supplier`

INSERT INTO `supplier` (`id`, `name`, `category_id`) VALUES

(1, ‘Supplier  Cat 1’, 1),

(2, ‘Supplier 2 Cat 1’, 1),

(3, ‘Supplier Cat 3’, 3),

(4, ‘Supplier Cat 4’, 4),

(5, ‘Supplier 2 Cat 2’, 2);

— ——————————————————–

— Table structure for table `users`

CREATE TABLE IF NOT EXISTS `users` (

`userid` int(11) NOT NULL AUTO_INCREMENT,

`username` varchar(100) NOT NULL,

`password` varchar(100) NOT NULL,

PRIMARY KEY (`userid`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

— Dumping data for table `users`

INSERT INTO `users` (`userid`, `username`, `password`) VALUES

(1, ‘admin’, ‘admin’),

(2, ‘admin1’, ‘admin1’);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

DB Example 14-2-14

https://www.dropbox.com/s/6vujnjgnxsl034z/ci_add_edit_delete-14-2-14.zip

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: