0

個人が作成したコメントをテーブルから選択する必要があるアプリケーションに取り組んでいます..しかし、結果セットからデータを取得する際に問題があります..これは私の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 は初めてです... このサイトで解決策を確認しようとしましたが、問題を解決するものは得られません。

4

2 に答える 2

0

関数 get_comments() は、次のように表示できる fetchAll(Double array) の結果を返します。

 $main_comments=$comments->get_Comments();
$this->view->$main_comments=$main_comments;/*make the varibles avelaible to the view*/

-適切なビューで:

<?php foreach ($this->main_comments as $item): ?>
    <?= $item['comment'] ?> 
    <?= $item['user....'] ?> <!-- Add your vars here and some HTML...  -->
<?php endforeach ?>

それが役に立てば幸い。

于 2013-06-19T10:34:57.013 に答える