1

I have this little bit of code and I want to return an array of strings after looping through the array and pushing the $id parameter to the array.

function getAdminEmail($id) {
    $query = executeQuery("SELECT email FROM system_users WHERE access='" . $id . "'");
    $emails = array();
    while($row = $query->fetch_assoc()) {
        array_push($emails,$row['email']);
    }

    return $emails;
}
Andronicus
  • 25,419
  • 17
  • 47
  • 88
Montrell Jubilee
  • 31
  • 1
  • 1
  • 6
  • first use `$emails = []` instead of `$emails = array();` due to this [link](https://stackoverflow.com/questions/26651996/) . did you try `array_push($emails,$row['email']);` and what's the result of this code? I think I didn't understand what do you want. – GameO7er Aug 17 '19 at 05:22

1 Answers1

0
function getAdminEmail($id) {
    $query = executeQuery("SELECT email FROM system_users WHERE access='" . $id . "'");

    return $query->fetch_all(MYSQLI_ASSOC);
}

Will return the results of the query in an associative array.

Also, look into using Prepared Statements instead of concatenating the $id in the string like that.

Hayden
  • 2,082
  • 1
  • 14
  • 18