php - How to call while loop from class? -
i have class getinfo.php , script welcome.php. inside info class have function getall. want call "first" variable $this->first , returning 1 value, want "first" in row.please see below
//script getinfo.php class getinfo{ function getall(){ global $conn; $sql = $conn->prepare("select * users"); $sql->execute(); while($row = $sql->fetch(pdo::fetch_assoc)){ $this->first = $row['first']; $this->last = $row['last']; $this->email = $row['email']; } } } //script welcome.php <?php $info = new getinfo(); $info->getall(); echo $info->first; //this returning 1 value, want row values. ?>
make list of array
class getinfo{ function getall(){ global $conn; $sql = $conn->prepare("select * users"); $sql->execute(); while($row = $sql->fetch(pdo::fetch_assoc)){ $this->first[] = $row['first']; $this->last[] = $row['last']; $this->email[] = $row['email']; } return $this; } }
Comments
Post a Comment