0

i have table (tag).. i want to select all tags in this table and return it as single array where tag_id = index and tag_name = value like this array

array(
            3 => 'Hazel Grouse',
            4 => 'Common Quail',
            5 => 'Common Pheasant',
            6 => 'Northern Shoveler',
            7 => 'Greylag Goose',
            8 => 'Barnacle Goose',
            9 => 'Lesser Spotted Woodpecker',
            10 => 'Eurasian Pygmy-Owl',
            11 => 'Dunlin',
            13 => 'Black Scoter',
)

tags return like this multi D array

Array
(
    [0] => Array
        (
            [tag_id] => 3
            [tag_name] => Hazel Grouse
        )

    [1] => Array
        (
            [tag_id] => 4
            [tag_name] => Common Quail
        )

this is query code

 function get_alltags() {
        $this->db->select('tag_id');
        $this->db->select('tag_name');
        $result = $this->db->get('d_tag');
     return $result->result_array();
    }
    $alltags = $this->tag->get_alltags();
        echo "<pre>";
        print_r($alltags);
        echo "</pre>";
        exit;
0

1 Answer 1

2

you can do something like this

$result=array();
$alltags = $this->tag->get_alltags();
foreach($alltags as $k => $v){
$result[$v['tag_id']]=$v['tag_name'];}
echo "<pre>";
print_r($result);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.