php syntax confusion accessing database result
Posted
by Babak
on Stack Overflow
See other posts from Stack Overflow
or by Babak
Published on 2010-03-12T13:04:59Z
Indexed on
2010/03/12
13:07 UTC
Read the original article
Hit count: 256
I am trying to do the following:
<?php foreach($sqlResult as $row): ?>
<tr>
<?php foreach($formdata['columns'] as $column): ?>
<td><?php echo $row->$column['name']; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
This does not work.
$row is returned by my mysql query, it has the following : row->id, row->author, row->name and these work as they echo fine.
$columns is the following array:
'columns' => array
(
1 => array
(
'name' => 'id'
),
2 => array
(
'name' => 'author'
),
3 => array
(
'name' => 'date'
),
4 => array
(
'name' => 'title'
)
it also works fine as $column['name'] echoes id, author, date, title
my question is how would it be possible for me to access the $row->method (is it a method?) by passing it a name from the array??
© Stack Overflow or respective owner