March 2, 2012

frustrated db query and getvalue in a view after failure

Question by Pablov Ivanov

After I print out a query of a list of user satisty some condition from my database I have got the following array

Array ([0]=>Array([users]=>Array([id]=>6 [username]=>sam [fullname]=>Sam Ho)))

But when I try to get the value in a view like
someone['fullname'] I have got nothing then

<?php
    foreach($users as $row)
    {
        ?>
        <h1>His name is <?php echo strtoupper($row['fullname']);?></h1>
        <?php
    }
?>

Answer by Starx

In your case, the following should work perfectly.

foreach($array as $key => $val) {
   echo $val['users']['id'];
   // and so on
}

I am assuming $array as your main array of records.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!