Welcome Guest, Not a member yet? Register   Sign In
[solved] get db result
#1

[eluser]kaejiavo[/eluser]
Hi guys,

i have a problem with a db result. My code:

Code:
function get_shop_items($shop_id) {
    $this->db->select('items_id');
    $this->db->where('shops_id', $shop_id);
    $this->db->from('item_shops');
    $query = $this->db->get();

    return $query->result_array();
    }

returns an array:
Code:
Array ( [0] => Array ( [items_id] => 3 ) [1] => Array ( [items_id] => 7 ) )

but i need:
Code:
Array ( [0] =>  3 [1] => 7 )
because i want to use it to select options in a form_multiselect.

Is there any way to return only the values with db library, or do i have to circle the values and build my own array?

TIA
Marco
#2

[eluser]WanWizard[/eluser]
Queries return records, so you'll have to convert it yourself.
#3

[eluser]CI_avatar[/eluser]
You should use

Code:
//return $query->result_array();
return $query->result();
#4

[eluser]kaejiavo[/eluser]
Hi,

thanks for your suggestions. I am converting the result now using
Code:
$query = $this->db->get();
    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
        $items[] = $row->items_id;
        }
    }
    return $items;

Marco
#5

[eluser]CI_avatar[/eluser]
Good work. keep it up marc
#6

[eluser]CI_avatar[/eluser]
Suggestion you can access table using
Code:
query   = $this->db->get();
$result = $query->result();

//i is index variable
echo $result[i]->TABLEFIELD1;
echo $result[i]->TABLEFIELD2;
echo $result[i]->TABLEFIELD3;
echo $result[i]->TABLEFIELD4;




Theme © iAndrew 2016 - Forum software by © MyBB