Array only returning one value
Posted: Fri Nov 18, 2011 10:32 am
hi guys I need some help with something that might appear really basic:
I have a table in db for registered users with all sorts of info including emails.
I wrote a function to return all emails but I'm having a few problems because it's only returning 1 email.
If I uncomment the echo in the function it gives- me all emails but when I call it on this page
only gives-me 1 email.
Any help I'll be very greatful
Thanks in advance,
Mike
I have a table in db for registered users with all sorts of info including emails.
I wrote a function to return all emails but I'm having a few problems because it's only returning 1 email.
Code: Select all
//THIS IS THE FUNCTION INSIDE MY CLASS
public function SelectEmailUser()
{
try{
$sql="SELECT email AS all_emails FROM registration Order BY id ASC";
$result = $this->db->mysqli->query($sql);
if(!$result)
{
throw new Exception("Query failed: " . $sql . " - " . $this->db->mysqli->error);
}else{
while($mymails = $result->fetch_assoc()){
$mails = $mymails['all_emails'];
$this->user_emails = $mails;
// echo $this->user_emails = $mails;
}
}
} catch(Exception $e){
echo("Message: " . $e->getMessage());
}
}
Code: Select all
//THIS IS THE PAGE WHERE i CALL IT
if("Send" == $_POST['submit'])
{
$get_emails_user = new Registration();
$get_emails_user->SelectEmailUser();
$userEmails = $get_emails_user->user_emails;
$allEmails = $adminEmails;
echo $userEmails;
only gives-me 1 email.
Any help I'll be very greatful
Thanks in advance,
Mike