phpgrocery-crud

getting column from mysql database in grocery crud


I want to create a dropdown with modified column data from database in grocery crud. My code is following

$this->db->select($column);
$temp = $this->db->get($table);
$temp1 = array();
foreach ($temp as $row)
{
    $temp1[] = $row[$column];
}

But this code is not working. I am getting error undefined index $column error. Where I am making mistake? I can't use grocery crud set_relation api since I need to modify database column data before passing it to drop down list.


Solution

  • I made a mistake in my code. The working code is following for grocery crud

    public function get_column($table, $column, $condition=null, $value=null)
    {
        $this->db->select($column);
        if ($condition != null)
        {
            $this->db->where($condition, $value);
        }
        $temp = $this->db->get($table);
    
        $temp_array = array();
        foreach ($temp->result() as $row)
        {
            $temp_array[] = $row->$column;
        }
        return $temp_array;
    }