Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPOOP:如何获取数据库值并返回所有值_Php_Database_Function_Return_Echo - Fatal编程技术网

PHPOOP:如何获取数据库值并返回所有值

PHPOOP:如何获取数据库值并返回所有值,php,database,function,return,echo,Php,Database,Function,Return,Echo,我试图从数据库中获取所有结果并将其返回到屏幕,问题是一旦我“回显”了值,它们都会显示出来,但当我使用“返回”时,只有1个显示出来 我不能使用echo,因为我的应用程序是以一种将html放入函数的方式构建的,这样我就可以填充对象,然后填充页面的内容 这是我的密码 public function read() { $query = "SELECT id, title, description, datetime FROM seminar"; $result = $this->g

我试图从数据库中获取所有结果并将其返回到屏幕,问题是一旦我“回显”了值,它们都会显示出来,但当我使用“返回”时,只有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;
}

使用数组。。推送databaseobjects并返回

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

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

} 

在调用者函数中,放置while循环并处理值。

函数在不同的类中,这有关系吗?不应该。。如果您正在调用thr类和函数coreCtly,我会这样尝试您的示例:公共函数read(){$query=“从研讨会中选择id、标题、描述、日期时间”;$result=$this->getDb()->query($query);$values=array();while($row=$result->fetchObject())!==false){//foreach($row as$values){$values['title']=$row->title;返回$values;//$this->setDescription($row->description);//$this->setDatetime($row->datetime);//}}但是我不知道如何填充渲染函数这些函数在不同的类中这有关系吗?这不是问题。无论从何处调用,它都会返回到该函数
public function read() {
    $query = "SELECT id, title, description, datetime FROM seminar";
    $result = $this->getDb()->query($query);
    return $result;
}