[eluser]nuwanda[/eluser]
Hi, All
Thought I'd share two utility snippets I use. Nothing too original but they may help someone.
Feel free to share yours. The mod may sticky this.
This one gets a field (what) from (where) containing (where_value).
Code:
function get_what_where($what, $where, $where_value, $table){
$this->db->select($what);
$this->db->where($where,$where_value);
$query=$this->db->get($table);
if($query->num_rows==1){
return $query->row($what);
}else
return 0;
}
}
This updates a field (what) with (what_value) from (where) containing (where_value).
Code:
function put_what_where($what,$what_value,$where,$where_value,$table){
$this->db->set($what,$what_value);
$this->db->where($where,$where_value);
if($this->db->update($table)){
return 1;
}
return 0;
}
Both return either success or failure.