我正在开发一个应用程序,我需要从表中选择个人发表的评论..但是在从结果集中检索数据时遇到问题..这是我的 sql 语句
public function get_Comments()
{
$select=$this->_db->select()
->from('comments',array('id','comment','user_id'));
$result=$this->getAdapter()->fetchAll($select);
return $result;
}
我已经在我的控制器中接收到数据并以这种方式操作.. $comments=new Application_Model_DbTable_Procedure(); $main_comments=$comments->get_Comments();
$result=(array) $main_comments;
print_r($result);
我还没有将数据带到视图中,只是想直接从控制器显示它,然后再移动它。这是我得到的数组
Array ( [0] => Array ( [id] => 1 [comment] => how is attachment in safaricom [user_id] => 2 ) [1] => Array ( [id] => 2 [comment] => hello world [user_id] => 2 ) [2] => Array ( [id] => 3 [comment] => how is attahment in kra [user_id] => 2 ) [3] => Array ( [id] => 16 [comment] => how is attachment in kra? [user_id] => 3 ) [4] => Array ( [id] => 17 [comment] => hello world [user_id] => 2 ) [5] => Array ( [id] => 18 [comment] => this is me trying everythin out [user_id] => 2 ) [6] => Array ( [id] => 19 [comment] => am testing system [user_id] => 3 ) )
I wanted to get the result in three columns:
id comment user_id
我曾尝试使用 foreach 循环,但无法获得结果....我是 zend 的新手...我尝试在此站点中检查解决方案,但找不到任何解决我的问题的方法。