Problem with printing data from an array

Asked

Viewed 21 times

0

I have two Row and mailTeste arrays, one of them comes from my database and is already populated, within it has two Row["email"] and Row["id] I want to pass to my other array that will be used inside a foreach to print the results on the screen, I intend to use this mailTeste to make comparisons with future data additions in this database.

The problem is that I am unable to pass Row data to my Mailteste array.

$query = "SELECT TabelaX.email, TabelaX.id, TabelaY.whitelist FROM email   RIGHT JOIN whitelist ON TabelaX.id = TabelaY.sid WHERE rid='0' ORDER BY email";
$result = mysql_query($query);
$W_list = "";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $Email_ot = array(
        $row["email"] => $row["id"]
    );
}

In this top code block I take the data (email and id) of the database and step to Row, soon after create the $mailTeste array to save the information.

foreach ($Email_ot as $email => $id) {
    if (in_array($email, $wlistTeste)) {
        echo "existe no array<br>";
    } else {
        echo "não existe: ";
        printf($email . '<br>');
    }
}

This foreach is used to confirm that the data that has been placed inside an input is already in the database.

  • Where is the array mailTeste? I didn’t see her in the code presented.

1 answer

0


The problem is that in the while command you are creating a new array for each iteration... Then for each row the query returns, instead of adding in the array you delete the array and create a new array.

You need to create the variable $Email_ot before the while and use it inside the while.

// ...
$Email_ot = array();
while(...) {
    $Email_ot [$row["email"]] = $row["id"];
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.