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:
private function Get_Members_From_DB()
{
$sql = "SELECT
Email, FirstName, LastName, Gender
FROM
member";
$result = mysqli_query($this->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->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->Con, $sql);
while($row = mysqli_fetch_array($result))
{
$arrayResult[] = $row;
}
return ($arrayResult);
}
When I call these, I get Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given
on line 406, which is while($row = mysqli_fetch_array($result))
. I also get Fatal error: Cannot use object of type Club as array in
on line 48 which is echo("<tr><td>" . $row1['FirstName'] . " " . $row1['LastName'] . "</td><td>" . $row1['Email'] .
I have tried several versions of this, and I cannot seem to get the data to work into the following function:
public function DisplayMembers()
{
//$members[] = array();
$interests[] = array();
$members = new Club();
$members->Get_Members_From_DB();
echo ("<table id='membertable'><tr><td colspan='4'>Informatics Club Members</td></tr>
<tr><td width='130px'>Name</td><td width='170px'>Email</td><td width='60'>Gender</td>
<td width='280px'>Interests</td></tr>");
while($row1 = $members)
{
echo("<tr><td>" . $row1['FirstName'] . " " . $row1['LastName'] . "</td><td>" . $row1['Email'] .
"</td><td>" . $row1['Gender'] . "</td><td><ul>;");
$results2 = new Club;
$results2->Get_Members_Interests_From_DB($row1['Email']);
while($row2 = mysqli_fetch_array($results2))
{
$interests[] = $row2;
echo("<li>" . $row2['InterestDescription'] . "</li>");
}
echo("</ul></td></tr>");
};
echo "</table><br>";
}
I had changed private function Get_Members_From_DB()
to:
$sql = "SELECT
Email, FirstName, LastName, Gender
FROM
member";
$result = mysqli_query($this->Con, $sql); return ($result);
And it still does not work in the DisplayMembers()
function with out getting the first error I posted above, except it would be on line 46, which would be changed to: while($row1 = mysqli_fetch_array($members))
If I take the above code and paste it directly into DisplayMembers()
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?
EDIT: I am calling these private functions from a public function inside the SAME class.