Welcome Guest, Not a member yet? Register   Sign In
Echo a single entry from a single DB returned array.
#1

[eluser]mflammia[/eluser]
Sorry if this is a simple but really struggling to find an answer.

Have the following array returned to the view from a single DB query:

Code:
<?PHP
        echo "<pre>";
print_r($person);
echo "<pre>";
?&gt;

Code:
Array
(
    [0] => stdClass Object
        (
            [id_person] => 95
            [first_name] => Abbey
            [second_name] => Nobody
            [dob] => 1973-09-16
            [email] =>
            [phone] =>
        )

)

I can get something like the first name to display by doing something like the following:

Code:
&lt;?php foreach($person as $row):?&gt;
&lt;?php echo $row->first_name ?&gt;
&lt;?php endforeach;?&gt;

Which seems a long winded / incorrect why to go about something that only has one record.

I've tried every combination of coding to just echo a single part of the array, with just a few like:

Code:
echo $person[0]['first_name'];
echo $person ['first_name'];
echo $person->firstname;

Without any luck.

Help much appreciated in advance


Messages In This Thread
Echo a single entry from a single DB returned array. - by El Forum - 04-06-2012, 10:52 AM
Echo a single entry from a single DB returned array. - by El Forum - 04-06-2012, 12:44 PM
Echo a single entry from a single DB returned array. - by El Forum - 04-06-2012, 01:45 PM
Echo a single entry from a single DB returned array. - by El Forum - 04-06-2012, 02:42 PM
Echo a single entry from a single DB returned array. - by El Forum - 04-06-2012, 04:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB