Hello,
I am working through the iterator pattern but when I try to loop through the array to build the table, I am getting Notice: Trying to get property of non-object errors.
I am using information from a database that I have build, same type of relationship $name, $email, $communityGear. So If I do a var_dump I am getting the following.
object(searchBySolorooerIterator)#1 (2) { ["__solorooerDetails:private"]=> array(1) { [0]=> object(solorooer)#4 (3) { ["name"]=> string(10) "Mike" ["email"]=> string(27) "
[email protected]" ["communityGear"]=> array(2) { [0]=> string(7) "Doritos" [1]=> string(5) "Water" } } } ["__valid:private"]=> bool(false) }
Here is my construct function, I did things a little differently, but it should work.
Code:
public function __construct($email) {
$sql = "SELECT user.solo_ID, user.solo_Name, user.solo_Email, bbq.bbq_ItemName
FROM user
LEFT JOIN bbq
ON user.solo_ID = roo_bbq_beerbq.bbq_SoloID
WHERE user.solo_Email = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $email);
$stmt->execute();
$solorooerID = 0;
$solorooer = NULL;
$stmt->bind_result($solo_ID, $solo_Name, $solo_Email, $bbq_ItemName);
while ($stmt->fetch()) {
if ($solo_ID !== $solorooerID) {
if (!is_null($solorooer)) {
$this->__solorooerDetails[] = $solorooer;
}
$solorooerID = $solo_ID;
$solorooer = new solorooer($solo_Name, $solo_Email);
}
$solorooer->addGear($bbq_ItemName);
}
$this->__solorooerDetails[] = $solorooer;
$stmt->free_result();
$stmt->close();
$conn->close();
}
Thanks In Advanced
Mike Moore