How to display the id value from two tables b / d advert and category. At this time, it displays only the value of $ adver-> id.

public function actionIndex() { $advert = Advert::model()->findAllBySql('SELECT * FROM o_advert'); $this->render('index', array('model' => $advert)); $c = Advert::model()->findAllBySql('SELECT * FROM o_category'); $this->render('index', array('model' => $c)); } <?php foreach (array_reverse($model) as $adver) { ?> <?php echo $adver->id; ?> <?php echo $adver->title; ?> <?php } ?> <?php foreach ($model as $c) { ?> <?php echo $c->id; ?> <?php echo $c->description; ?> <?php } ?> 

    2 answers 2

    The problem is that in the view you rewrote $ model. You just need to place the result of the sample in different variables.

     $this->render('index', array('a_model'=> $advert)); .... $this->render('index',array('c_model'=> $c)); ... <?php foreach (array_reverse($a_model) as $adver) { ?> <?php echo $adver->id; ?> <?php echo $adver->title; ?> <?php } ?> <?php foreach ($c_model as $c) { ?> <?php echo $c->id; ?> <?php echo $c->description; ?> <?php } ?> 

      Describe the task in a little Russian, I actually read it 3 times and did not understand.

      How to display the value of the columns of two tables with the same name

      2 tables with the same name, or the tables have the same fields

       <?php foreach (array_reverse($model) as $adver) { ?> <?php echo $adver->id; ?> <?php echo $adver->title; ?> <?php } ?> <?php foreach ($model as $c) { ?> <?php echo $c->id; ?> <?php echo $c->description; ?> <?php } ?> 

      Is that code on php ????

      if you are writing such a "nonsense" so even into the logic of insight.

      public function actionIndex () {$ advert = Advert :: model () -> findAllBySql ('SELECT * FROM o_advert');
      $ c = Advert :: model () -> findAllBySql ('SELECT * FROM o_category');
      $ this-> render ('index', array ('m' => $ advert, 'mo' => $ c)); }

       <?php foreach (array_reverse($m) as $adver) { echo $adver->id; echo $adver->title; } foreach ($mo as $c) { echo $c->id; echo $c->description; } ?> 

      I understand everything, but the syntax is not just lame, it has not even been born yet.