Foreach As Function

Hello.

I have Join function:


  public function getFormQuest() {

        $select = Yii::app()->db->createCommand()

                ->select('pytanie')

                ->from('quest_open p')

                ->join('odp_open_form o', 'p.id=o.quest_open_id')

                ->where('form_id=' . $this->id . '')

                ->queryAll();

    }

And in view :


<?php $model->getFormQuest();?>

How i can get foreach in view, where my question must by render.

Hello.

You have to return the array then only you can get array in view and then using forwach loop u can retrive data.

your function shold be like this as follow:


  public function getFormQuest() {

        $select = Yii::app()->db->createCommand()

                ->select('pytanie')

                ->from('quest_open p')

                ->join('odp_open_form o', 'p.id=o.quest_open_id')

                ->where('form_id=' . $this->id . '')

                ->queryAll();

        return $select;

    }

And in view :


<?php 

$model->getFormQuest();?>

How i can get foreach in view, where my question must by render.

[/quote]

Now i do that, but in view doesn;t render my question.

But when i do that:


public function getFormQuest() {

        $select = Yii::app()->db->createCommand()

                ->select('pytanie')

                ->from('quest_open p')

                ->join('odp_open_form o', 'p.id=o.quest_open_id')

                ->where('form_id=' . $this->id . '')

                ->queryAll();

        var_dump($select);

    }

I get in view:


array (size=3)

  0 => 

    array (size=1)

      'question' => string 'question 1?' (length=11)

  1 => 

    array (size=1)

      'question' => string 'question 2?' (length=11)

  2 => 

    array (size=1)

      'question' => string 'question 3?' (length=11)

public function getFormQuest() {

    &#036;select = Yii::app()-&gt;db-&gt;createCommand()


            -&gt;select('pytanie')


            -&gt;from('quest_open p')


            -&gt;join('odp_open_form o', 'p.id=o.quest_open_id')


            -&gt;where('form_id=' . &#036;this-&gt;id . '')


            -&gt;queryAll();


    return &#036;select;


}

and in the view file

<?php

&#036;data = &#036;model-&gt;getFormQuest();


print_r(&#036;data);exit;

?>

This will 100% work…I have tried …

yeah man :) its works :) Sorry .

I now have that:

Question 1

replies for question 1

replies for question 2

replies for question 3

Question 2

replies for question 1

replies for question 2

replies for question 3

Question 3

replies for question 1

replies for question 2

replies for question 3

I need :

Question 1

replies for question 1

Question 2

replies for question 2

Question 3

replies for question 3