3

I have the following query:

$usersTable = new Users();

$rowset = $usersTable->select()
    ->setIntegrityCheck(false)
    ->where( 'id = ?', $userId )
    ->join( 'Books', 'Books.userid = Users.id' );

However, I can't for the life of me figure out how to read the resulting rowset (the list of books associated with the user).

Would I do the following?

foreach ($book in $rowset->Books) {
    print_r($book["book_name"]);
}
Wouter Dorgelo
  • 11,770
  • 11
  • 62
  • 80
romiem
  • 8,360
  • 7
  • 29
  • 36

2 Answers2

0

Try something like:

$sql = $this->select()
->setIntegrityCheck(false)
->where( 'id = ?', $userId )
->join( 'Books', 'Books.userid = Users.id' )
);
$rowset = $this->fetchRow($sql);
foreach ($rowset as $book) {
    print_r($book["book_name"]);
}

Is this going in your model?

Adam
  • 1,098
  • 1
  • 8
  • 17
  • I'm afraid this wont work, because you use joins in your select. You should use getAdapter before fetching. – mik Dec 01 '10 at 15:05
0

What you call $rowset is actually an sql expression. This should work:

$usersTable = new Users();

$sql = $usersTable->select()
    ->setIntegrityCheck(false)
    ->where( 'id = ?', $userId )
    ->join( 'Books', 'Books.userid = Users.id' );
$rowset = $usersTable->getAdapter()->fetchAll($sql);
mik
  • 1,575
  • 6
  • 22
  • 33