PHP - Get values from Array
Posted
by danit
on Stack Overflow
See other posts from Stack Overflow
or by danit
Published on 2010-03-26T19:22:19Z
Indexed on
2010/03/26
19:33 UTC
Read the original article
Hit count: 105
php
I am trying to get a record from a database using an sql lookup (sql1). This then returns as an array which is fine, but I need to use part of the array for my next stage.
$opt=get_records_sql($sql1);
//Diags for SQL content
print_object($opt);
$n = count($opt);
if (empty($opt))
{
echo 'No options selected';
}
else
{
$optno = $opt["subjectid"];
// Diags of $optno
echo '<br>$optno = '.$optno;
As you can see, I tried to use this: $opt["subjectid"] as subjectid is the fieldname that I am trying to access and I was under the impression that this was correct for accessing an array, but I get the following error:
Notice: Undefined index: subjectid
Array contents:
Array
(
[1] => stdClass Object
(
[uname] => JHollands06
[tutor] => M LSt
[subjectid] => 1
[year] => 2010
[optid] => 1
)
)
© Stack Overflow or respective owner