Faisal Sharif
Faisal Sharif

Reputation: 24

How to Arrange array data in codeigniter

i am getting this output from database data

i am using codeigniter 3

Array
(
    [0] => stdClass Object
        (
            [umeta_id] => 72
            [user_id] => 4
            [meta_key] => nickname
            [meta_value] => John ALbert
        )

    [1] => stdClass Object
        (
            [umeta_id] => 73
            [user_id] => 4
            [meta_key] => first_name
            [meta_value] => John
        )

    [2] => stdClass Object
        (
            [umeta_id] => 74
            [user_id] => 4
            [meta_key] => last_name
            [meta_value] => Albert
        )
)

but can i get data like this

Array
(
  [nickname] => John ALbert
  [first_name] => John
  [last_name] => Albert
)

i want like this if anyone help me i would be thankful

Upvotes: 0

Views: 51

Answers (1)

ym y
ym y

Reputation: 87

It is possible to receive the result of SQL processing as an array type.

The source code below is included in the CodeIgniter manual.

$query = $this->db->query("YOUR QUERY");

if ($query->num_rows() > 0)
{
        $row = $query->row_array();

        echo $row['title'];
        echo $row['name'];
        echo $row['body'];
}

Upvotes: 1

Related Questions