我试图从数据库中获取所有结果并将它们返回到屏幕,问题是一旦我“回显”值它们都显示出来,但是当我使用“返回”时只有 1 显示。
我不能使用 echo,因为我的应用程序是建立在将 html 放入函数的方式上的,因此我可以填充对象,然后填充页面的内容。
这是我的代码。
public function read() {
$query = "SELECT id, title, description, datetime FROM seminar";
$result = $this->getDb()->query($query);
while(($row = $result->fetchObject()) !== false) {
foreach($row as $value) {
return $row->title;
//$this->setDescription($row->description);
//$this->setDatetime($row->datetime);
}
}
}
现在我想知道如何在屏幕上获取所有值,而不仅仅是现在显示的值。
public function setSeminar($sem_obj) {
$this->sem_obj = $sem_obj;
}
public function render() {
$this->content = '
On this page you can see all items.
';
$this->content .= $this->sem_obj->getTitle();
$this->content .= $this->sem_obj->getDescription();
$this->content .= $this->sem_obj->getDatetime();
//$this->content .= $this->text1->showSeminairs();
return $this->content;
}