foreach或仅显示最后结果

时间:2019-08-11 14:45:46

标签: php

此结构仅在foreach上有几页,或者仅显示最后一个结果,这个问题是在我执行此功能后发生的,我已经看到了几个问题,并且与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);

1 个答案:

答案 0 :(得分:0)

我不确定,但我认为您正在寻找类似的东西:

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);