0

A simple select of this form:

            $select = $this->select();
            return $rowset = $this->fetchAll($select);

Now, There is an inherit column in the array, so the table is of the form:

   id   |   role   |   inherits   |
   1    |   admin  |    2         |
   2    |   player |    3         |

And When displayed I would like the inherirs column to show the Role it actually inherits from instead of the id.

The array returned by Zend_Db_Table_Abstract is extremely convoluted, so I can't just say:

$array[0][inherits]

1 Answer 1

1

First of all $this->fetchAll will not return array it is going to return Zend_Db_Table_Rowset_Abstract object. You can learn more about it here in Zend_Db_Table_Rowset Zend Docs.

You can get data from it as an object

// use Zend_Db_Table_Row_Abstract object
$array[0]->inherits

Or if you want to get an array you can do this:

// get rowset and convert it to array
$rowset = $this->fetchAll($select);
$data = ($rowset) ? $rowset->toArray() : array();

Better solution would be to write a left join on the same table and get the role in the dataset without any PHP code.

$sql = $this->getAdapter()->select()
        ->from(array('r1' => 'your_roles_table'), '*')
        ->joinLeft(array('r2' => 'your_roles_table'), 'r2.id = r1.inherits', array(
            'inherits_role' => 'r2.role',
        ));

$data = $this->getAdapter()->fetchAll($sql);
var_dump($data);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.