php - return all object created in loop -


I am new to PHP OOP, I am trying to select the OOP, I have

  

class page {var $ title; Function Settlement ($ title) {$ this- & gt; Title = $ title;}}

now

  class model {connection $ done; Function receivedApplepage () {$ query3 = "select * from pages"; $ Result3 = mysqli_query ($ this->; $ query3); While ($ rows = mysqli_fetch_array ($ result3)) {$ page = new page; $ Page- & gt; SetP_title ($ rows ['p_title']); } Return $ page; }}  

  class controller {function index AllPage () {$ pages = $ this- & gt; Conn- & gt; GetAllPages (); ('Allpages.php'); }}  

see allpages.php

If you want to return more than one page then you need an array:

  $ pages = array (); While ($ rows = mysqli_fetch_array ($ result3)) {$ page = new page; $ Page- & gt; SetTitle ($ rows ['p_title']); $ Pages [] = $ page; } Return $ page;  

Update:

$ pages = $ this- & gt; Conn- & gt; GetAllPages (); // $ pages now have an array, so you have to loop through it or get a specific index // $ $ $ $ Get the first page from the page $ [0]; // Loop foreach through ($ page $ page) {$ title = $ page- & gt; GetTitle (); }

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -