Reference for important codes:
To display query built by active record
print_r($query);
To display values in an array
echo var_dump ($array);
Build statement with active record
$this->db->select('*');
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');
$query = $this->db->get();
Auto detect domain to get base_url
$domain = $_SERVER['SERVER_NAME']; $config['base_url'] = "http://".$domain."/your_app";
Drop down
//model
$result = $this->db->get();
$array = array();
if($result->num_rows() > 0) {
foreach($result->result_array() as $row) {
$array[$row['courseid']] = $row['coursename'];
}
}
return $array;
//view
echo form_dropdown('fieldname', $listarray, $selecteddata,'other_form_attributes');
Add/delete form variables (in controller)
$data['editmode'] = true;
$data['title'] = lang('title_batch_update');
$data['submitvalue'] = lang('label_update');
$data['formaction'] = site_url('batch/update');
Active record to get row and fields
$result = $this->db->get('tablename');
echo $result->row('name');
//or simply
$this->db->get()->result()->row('name');
Get last run query
$this->db->last_query();
For PHP empty($var) function:
The following things are considered to be empty: "" (an empty string) 0 (0 as an integer) 0.0 (0 as a float) "0" (0 as a string) NULL FALSE array() (an empty array) $var; (a variable declared, but without a value)