Welcome Guest, Not a member yet? Register   Sign In
Possible to return database row with a key instead as numeric indexes?
#1

[eluser]Unknown[/eluser]
For example if I do

Code:
Select * from Persons

Where Person has the columns: Name (Primary Key), Address, Phone

And I turn the returned Rows as an array I'll get

Code:
[0] => Array
        (
            [Name] => John Mang,
            [Address] => 123 Fake St,
            [Phone] => 1234567
        )

[1] => Array
        (
            [Name] => George Mang,
            [Address] => 123 Not Fake St,
            [Phone] => 555555
        )

But is there a way to get it so it'll be like

Code:
["John Mang"] => Array
        (
            [Name] => John Mang,
            [Address] => 123 Fake St,
            [Phone] => 1234567
        )

["George Mang"] => Array
        (
            [Name] => George Mang,
            [Address] => 123 Not Fake St,
            [Phone] => 555555
        )

Thanks.
#2

[eluser]rufnex[/eluser]
You have to reorganize your result array like that for e.g.

Code:
$result = $query->result_array();
            $hash = array();
            foreach ($result as $array)
            {
                $hash[$array['Name']] = $array;
            }
            print_r($hash);




Theme © iAndrew 2016 - Forum software by © MyBB