Code Ref

Reference for important codes:

To display query built by active record


To display values in an array

echo var_dump ($array);

 Build statement with active record

$this->db->join('comments', ' =');
$query = $this->db->get();

Auto detect domain to get base_url

$domain = $_SERVER['SERVER_NAME'];
$config['base_url'] = "http://".$domain."/your_app";

 Drop down

$result = $this->db->get();
$array = array();
if($result->num_rows() > 0) {
 foreach($result->result_array() as $row) {
   $array[$row['courseid']] = $row['coursename'];
return $array;

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

 Get last run 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)
array() (an empty array)
$var; (a variable declared, but without a value)

Leave a Reply

Your email address will not be published. Required fields are marked *