Yii Framework Forum: Foreach As Function - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Foreach As Function Rate Topic: -----

#1 User is offline   kopecldz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 86
  • Joined: 20-February 13

Posted 28 May 2013 - 06:24 AM

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.
0

#2 User is offline   Sukunj Mendpara 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 16-July 12
  • Location:Ahmedabad

Posted 28 May 2013 - 07:00 AM

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]
0

#3 User is offline   kopecldz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 86
  • Joined: 20-February 13

Posted 28 May 2013 - 07:14 AM

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)

0

#4 User is offline   Sukunj Mendpara 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 16-July 12
  • Location:Ahmedabad

Posted 29 May 2013 - 01:48 AM

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 the view file

<?php
$data = $model->getFormQuest();
print_r($data);exit;
?>

This will 100% work...I have tried ..
0

#5 User is offline   kopecldz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 86
  • Joined: 20-February 13

Posted 29 May 2013 - 01:56 AM

View PostSukunj Mendpara Rudra Soft, on 29 May 2013 - 01:48 AM, said:

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 the view file

<?php
$data = $model->getFormQuest();
print_r($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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users