0

I can't get the result for the fetch_array function. Any idea what is happening?

    $db = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$aa = htmlspecialchars($_POST['aa'], ENT_QUOTES);
            $sqlc = "SELECT * FROM oc_user WHERE username='".$aa."'";
            $resultc = $db->query($sqlc);

            if ($resultc === TRUE) {
            // manager email
            $mngemail = "";

                       while ($row = $resultc->fetch_array(MYSQLI_ASSOC)) {    
                            $mngemail .= $row['email'];
                       }
        echo 'email:'.$mngemail;
3
  • Can you be more specific on what isn't working? Error message perhaps? Commented Apr 29, 2015 at 18:49
  • I can't output the $mngemail variable. Commented Apr 29, 2015 at 18:52
  • That isn't necessarily where your problem is originating though. Can you var_dump() the contents of $resultc or $row in your loop? Does the output match your intended results? Is PHP outputting any error messages? The answers to these questions will be useful to help debug your situation. Commented Apr 29, 2015 at 18:56

1 Answer 1

2

You need to assign the returned value from fetch_array to $row

ie:

while ($row = $resultc->fetch_array(MYSQLI_ASSOC)) {       
    $mngemail .= $row['email'];
}
Sign up to request clarification or add additional context in comments.

2 Comments

Not sure what db wrapper you are using, but check if you have a num_rows() function of some sort, ensure you are actually getting data back. If you are, then put some output in the while loop like var_dump($row). Ensure you are getting back the data you expect
yes, I'm getting data. Now I'm getting 'array' for $mngemail variable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.