0

I am getting a specific row in a database with codeigniter / php /active record. I a would like to return the result as an array of the row's columns that can be referenced like this:

result[0] = column1
result[1] = column2
...

This is my current query:

public function get_instance($instanceID = NULL){
    $this->db->select('organism, feature, goal');
    $this->db->from('extra_instances');
    $this->db->where('id', $instanceID);
    $query = $this->db->get();
    return $query->row_array();
}

$data['instance'] = $this->instances_model->get_instance($instanceID);

But currently, to echo these, I (think) I need to give the name of the column, like:

<?php echo($instance['goal']) ; ?>

Is there a way to do this so I can say:

<?php echo($instance[2]) ; ?>
mheavers
  • 29,530
  • 58
  • 194
  • 315
  • Check [this one](http://stackoverflow.com/questions/6384761/quickest-way-to-replace-associative-array-keys-with-numerical-keys). Is that you need? – Tpojka Nov 03 '15 at 01:26

1 Answers1

0

You can do this by create a new array and assigns all values of old array to new array.

You can use the array_values() function to do this. Here is the example. so you can get more idea.

public function get_instance($instanceID = NULL){
    $this->db->select('organism, feature, goal');
    $this->db->from('extra_instances');
    $this->db->where('id', $instanceID);
    $query = $this->db->get();
    $results = $query->row_array();
    return array_values($results);
}
Anam Shah
  • 319
  • 1
  • 10