0

データベースからすべての結果を取得して画面に返そうとしていますが、値を「エコー」するとすべて表示されますが、「リターン」を使用すると1つしか表示されません。

私のアプリケーションは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;
}
4

2 に答える 2

0

配列を使用します。データベースオブジェクトをプッシュして、それを返します。

$tempArray=array();
while(($row = $result->fetchObject()) !== false) {

      $tempArray['title']=$row->title;
     $tempArray['description']=$row->description;
      return $tempArray;

} 
于 2013-03-18T08:29:34.313 に答える
0
public function read() {
    $query = "SELECT id, title, description, datetime FROM seminar";
    $result = $this->getDb()->query($query);
    return $result;
}

呼び出し元関数に while ループを入れて値を処理します。

于 2013-03-18T08:32:21.460 に答える