title: PHP - Calling Private Function within the Class Displaying MySQL Data
body: <p>I have a class Club{} that has several public functions and private functions.  The three private functions I have are used to get data from my database. Here is the following code:</p>
  
  <pre><code>private function Get_Members_From_DB()
      {
          $sql = "SELECT
                      Email, FirstName, LastName, Gender
                  FROM
                      member";
  
          $result = mysqli_query($this-&gt;Con, $sql);
  
          $arrayResult = array();
  
          while($row = mysqli_fetch_array($result))
          {
              $arrayResult[] = $row;
          }
  
          return ($arrayResult);
      }
  
      private function Get_Members_Interests_From_DB($MemberEmail)
      {
          $sql = "SELECT 
                      interest_type.InterestDescription
                  FROM
                      member, member_interests, interest_type
                  WHERE
                      member.Email = '$MemberEmail'
                  AND
                      member.Email = member_interests.Email
                  AND
                      member_interests.InterestID = interest_type.InterestID";
  
          $result = mysqli_query($this-&gt;Con, $sql);
  
          while($row = mysqli_fetch_array($result))
          {
              $arrayResult[] = $row;
          }
  
          return ($arrayResult);
      }
  
      private function Get_Interests_Types_From_DB()
      {
          $sql = "SELECT 
                      InterestID,
                      InterestDescription
                  FROM
                      interest_type";
  
          $result = mysqli_query($this-&gt;Con, $sql);
  
          while($row = mysqli_fetch_array($result))
          {
              $arrayResult[] = $row;
          }
  
          return ($arrayResult);
      }
  </code></pre>
  
  <p>When I call these, I get Warning: <code>mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given</code> on line 406, which is <code>while($row = mysqli_fetch_array($result))</code>.  I also get <code>Fatal error: Cannot use object of type Club as array in</code> on line 48 which is <code>echo("&lt;tr&gt;&lt;td&gt;" . $row1['FirstName'] . " " . $row1['LastName'] . "&lt;/td&gt;&lt;td&gt;" . $row1['Email'] .</code></p>
  
  <p>I have tried several versions of this, and I cannot seem to get the data to work into the following function:</p>
  
  <pre><code>public function DisplayMembers()
      {   
          //$members[] = array();
          $interests[] = array();
          $members = new Club();
          $members-&gt;Get_Members_From_DB();
  
          echo ("&lt;table id='membertable'&gt;&lt;tr&gt;&lt;td colspan='4'&gt;Informatics Club Members&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td width='130px'&gt;Name&lt;/td&gt;&lt;td width='170px'&gt;Email&lt;/td&gt;&lt;td width='60'&gt;Gender&lt;/td&gt;
                  &lt;td width='280px'&gt;Interests&lt;/td&gt;&lt;/tr&gt;");
  
          while($row1 = $members)
          {
              echo("&lt;tr&gt;&lt;td&gt;" . $row1['FirstName'] . " " . $row1['LastName'] . "&lt;/td&gt;&lt;td&gt;" . $row1['Email'] . 
                      "&lt;/td&gt;&lt;td&gt;" . $row1['Gender'] . "&lt;/td&gt;&lt;td&gt;&lt;ul&gt;;");
  
              $results2 = new Club;
              $results2-&gt;Get_Members_Interests_From_DB($row1['Email']);
  
              while($row2 = mysqli_fetch_array($results2))
              {
                  $interests[] = $row2;
                  echo("&lt;li&gt;" . $row2['InterestDescription'] . "&lt;/li&gt;");
              }
  
              echo("&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt;");
          };
  
          echo "&lt;/table&gt;&lt;br&gt;";
  }
  </code></pre>
  
  <p>I had changed <code>private function Get_Members_From_DB()</code> to:</p>
  
  <pre><code>$sql = "SELECT
                      Email, FirstName, LastName, Gender
                  FROM
                      member";
  
          $result = mysqli_query($this-&gt;Con, $sql); return ($result);
  </code></pre>
  
  <p>And it still does not work in the <code>DisplayMembers()</code> function with out getting the first error I posted above, except it would be on line 46, which would be changed to: <code>while($row1 = mysqli_fetch_array($members))</code>  If I take the above code and paste it directly into <code>DisplayMembers()</code> I can get the function to display correctly as an HTML table.  I do not understand why I am getting errors when I separate the code into the private function. Any ideas?</p>
  
  <p>EDIT: I am calling these private functions from a public function inside the SAME class.</p>