I query the db and when I use print_r()
I get the expected output, but when I feed the output into a foreach
loop I don't get the values.
My Class with it's method:
class select_data {
public function get_parent_id($parent_email) {
//$parent_ids = array();
try {
$db = new database;
$conn = $db->databaseConnect();
$select_parent_ids_stmt = $conn->prepare('SELECT uid, parent_id, email_of FROM emails WHERE email_address =:parent_email LIMIT 2');
$select_parent_ids_stmt->bindParam(':parent_email', $parent_email, PDO::PARAM_STR);
$select_parent_ids_stmt->execute();
if($select_parent_ids_stmt->rowCount() === 1){
$parent_ids = $select_parent_ids_stmt->fetchAll(PDO::FETCH_OBJ);
}
$conn = NULL;
} catch (PDOException $e) {
echo 'Could not process your request at this time.';
}
//Resturn the result
return $parent_ids;
}
}
Here I call the the method:
$select_parent_ids = new select_data;
$parent_ids = $select_parent_ids->get_parent_id($parent_email);
From here I use print_r($parent_ids)
to see if I get the expected result and I do:
Then I have my foreach
loop. This is the code:
foreach ($parent_ids as $key => $value) {
$db_uid = $value->uid;
$parent_id = $value->parent_id;
$email_of = $value->email_of;
return $email_of;
}
After this, I am doing stuff based on the result, but that's not working because I only get a blank return where I would expect to get a return of Parent (based on the screenshot provided. I also tried $email_of = $value['email_of']
with the same empty result.
Can ant please try and look where I went wrong?