How to create auto updated/modified and created columns of a table in mysql


Your table should look like:


CREATE TABLE `new_table` (
  `id` bigint(20) NOT NULL auto_increment,  
  `modified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `created` timestamp NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
)

To get the modified/created column changes you need to pass null value while updating or inserting values in a table. Please see the below example to make sense


/* Insert query: */

$pdata = array(	
	'modified' => null,
	'created' => null
);
$val = $this->db->insert('new_table', $pdata);

/* update query:  */

$pdata = array(
	'modified' => null
);
$this->db->where('id', $id);
$val = $this->db->update('new_table', $pdata);


Advertisements

Ajax call using jQuery with response type json at CodeIgniter


Now Ajax call using jQuery is very easy and simple . Have a look the codes how easy you can manipulate your Ajax call with out Reloading your web page and get your desire results.

This code should Paste on your view page :

<script type=”text/javascript” src=”http://code.jquery.com/jquery.min.js”></script&gt;
<script  type=”text/javascript”>
jQuery(document).ready(function(){
jQuery(‘#buton’).click(function(){
jQuery.ajax({
url: “<?php echo site_url(‘login/ajaxcall’); ?>”,
type: ‘POST’,
data:{ id : 5 },
dataType: “json”,
success: function(data){
var val = “<select name=\”user\”>”+
“<option>Select from below</option>”+
“<option>”+data.id+”</option>”+
“<option>”+data.name+”</option>”+
“<option>”+data.age+”</option>”+
“<option>”+data.sex+”</option>”+
“</select>”;
jQuery(‘#ans’).html(val);
},
error: function(data){
alert(data);
}
});
return false;
});

});
</script>

<center>
<button id=”buton” >Click And Get Ajax Value</button>
<p id=”ans”></p>
</center>

Now look how you can response according to the ajax request.This Code should be Paste on CodeIgniter Controller :

<?php

class Login extends CI_Controller{

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

}
public function ajaxcall(){

$data[‘id’]   = $this->input->post(‘id’);
$data[‘name’] = ‘Ziyed’;
$data[‘age’]  = ’24’;
$data[‘sex’]  = ‘Male’;

echo json_encode($data);

}

}

?>

 

 

 

CodeIgniter Pagination example using Version 2.0.2


Pagination using CodeIgniter is very easy to implement . Lets see an example with code segment .This code should be placed at Controller of CodeIgniter application folder :


<?php

class Controller_name extends CI_Controller{
 public function  __construct() {
   parent::__construct();
   $this->load->library('pagination');
 }
 public function index(){
  $basurl = base_url().'index.php/product/index';
  $config['base_url'] = $basurl;
  $config['total_rows'] = $this->db->get('products')->num_rows();
  $config['per_page'] = 10;
  $config['full_tag_open'] = '<p id="pagination" style="float: right;width:20%">';

  $config['full_tag_close'] = '</p>';
  $this->pagination->initialize($config);

  $res = $this->db->get('products', $config['per_page'], $this->uri->segment(3));
  $data['products'] = $res->result();

  $data['page'] = 'product';
  $this->load->view('layout',$data);
 }
 
}

?>

At CodeIgniter View >> layout ( i used this name at controller see before ) you should just Paste this code to see pagination link:


<?php

 echo $this->pagination->create_links();

?>

You can change outlook of pagination tag.Here is some css code:


<style>
#pagination a{
text-decoration:none;
color:black;
}
#pagination a:hover{
color:white;
}

#pagination strong{
color:blue;
font-size:20px;
}
</style>