simonmcm Posted May 1, 2010 Share Posted May 1, 2010 Hi I am using the ZEND FRAMEWORK and for some reason the results from this SQL statement aren't being displayed in the table: The query in the database model is as follows: public function getUsersBooks($userName) { $select = $this->select() ->from('books', array('title', 'author')) ->where('username = ?' ,$userName); $result = $this->getAdapter()->fetchAll($select); return $result; The controller is as follows: public function indexAction() { $this->authoriseUser(); $session = new Zend_Session_Namespace('MyNamespace'); $userName = $session->username; $books = new Model_DbTable_Books(); $this->view->books = $books->getUsersBooks($userName); } And the view is as follows: <table> <tr> <th>Title</th> <th>Author</th> </tr> <tr> <?php foreach($this->books as $book) : ?> <td><?php echo $this->escape($book->title);?></td> <td><?php echo $this->escape($book->author);?></td> <?php endforeach; ?> </tr> </table> if any one has any ideas why the results of the statement arnt being displayed it will be much apriciated Quote Link to comment https://forums.phpfreaks.com/topic/200393-problem-with-sql-statement-using-zend-framework/ Share on other sites More sharing options...
ignace Posted May 1, 2010 Share Posted May 1, 2010 if any one has any ideas why the results of the statement arnt being displayed it will be much apriciated The $username does not exist in the database or was not present in the session. Please, before asking questions make sure your data is what you expect it to be. Quote Link to comment https://forums.phpfreaks.com/topic/200393-problem-with-sql-statement-using-zend-framework/#findComment-1051638 Share on other sites More sharing options...
simonmcm Posted May 1, 2010 Author Share Posted May 1, 2010 I have checked that, the problem is the SQL statement isn't returning the output as an array, whats the syntax to output the result as an array????? Quote Link to comment https://forums.phpfreaks.com/topic/200393-problem-with-sql-statement-using-zend-framework/#findComment-1051669 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 I'm not familiar with the syntax, so forgive me for asking. What does this line do? Specifically, what's the array for? ->from('books', array('title', 'author')) Quote Link to comment https://forums.phpfreaks.com/topic/200393-problem-with-sql-statement-using-zend-framework/#findComment-1051697 Share on other sites More sharing options...
trq Posted May 2, 2010 Share Posted May 2, 2010 I have checked that, the problem is the SQL statement isn't returning the output as an array, whats the syntax to output the result as an array????? fetchAll() returns a Zend_Db_Table_Rowset_Abstract object which is what the syntax within your view is expecting, not an array like you keep talking about. As suggested by Ignace, I'm not sure your query is returning any results. You need to check your results before proceeding to use them. I'm not familiar with the syntax, so forgive me for asking. What does this line do? Specifically, what's the array for? ->from('books', array('title', 'author')) It selects the fields title & author from the books table. Quote Link to comment https://forums.phpfreaks.com/topic/200393-problem-with-sql-statement-using-zend-framework/#findComment-1051712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.