Hi,
I have a challenge which I can find a solution for so I thought posting here might help. I use PHP and codeigniter and this is what i am trying to do.
I run a query towards a database and have the result in a array like this:
[records] => Array (
[0] => stdClass Object (
[OPID] => 5
[OPName] => Red Hat
[Created] => Oct 7 2009 1:51PM )
[1] => stdClass Object (
[OPID] => 3
[OPName] => Windows 7
[Created] => Oct 7 2009 12:00AM )
[2] => stdClass Object (
[OPID] => 4
[OPName] => Windows Server 2003
[Created] => Oct 7 2009 11:17AM )
)
I then use a foreach loop going through the array, so to typical write for example OPID I would write like this
foreach $records as $row
echo $row->OPID;
endforeach;
so far so good and this is working. But I would like to reuse the code and get it more dynamic that is I would love to write something like this:
foreach $records as $row
echo $row[$field]; // something echo $row->$field;
endforeach;
In this case the $field would contain 'OPID' which I get from a $_POST in one example and 'APID' in another, all depending of what data the user do.
So my question, is it possible to have a dynamic value in a $row field like this to get it dynamic?
Cheers
Paal