猿问

foreach 或 while 只显示最后的结果

这个结构将有几个页面,只有 foreach 或 while 只显示最后一个结果,这个问题发生在我做了这个函数之后,我已经看到了几个问题,并且与 matriz 相关


class Layout {

   private $sql, $row;


   private function set_layout($cond, $cond_r) {


     $this->sql = $this->select("*", "table", "".$cond."", array($cond_r));

     foreach ($this->sql as $this->row) :

       return $this->row['name'];

     endforeach;


   }


   public function get_layout($cond, $cond_r) {

      return $this->set_layout($cond, $cond_r);

   }

}

echo $midia->get_layout("WHERE status != ? ORDER BY id DESC", 0);


慕慕森
浏览 125回答 1
1回答

天涯尽头无女友

我不确定,但我认为您正在寻找类似的东西:class Layout {private $sql, $row;    private function set_layout($cond, $cond_r) {        $this->sql = $this->select("*", "table", "".$cond."", array($cond_r));        $rows = array();        foreach ($this->sql as $this->row) :            $rows[] = $this->row['name'];        endforeach;        return implode($rows); //Return array of rows AFTER loop    }    public function get_layout($cond, $cond_r) {        return $this->set_layout($cond, $cond_r);    }}echo $midia->get_layout("WHERE status != ? ORDER BY id DESC", 0);
随时随地看视频慕课网APP
我要回答