1
I need to compare domain sent and processed by a form via $_POST
with domains of the database because I can only enter one email from each domain in the database. For this first I took the email from $_POST
and then stored all the base emails in an array with mysql_fetch_array
at the bank. Now, I need to get this array
return only domains as I did with explode which resulted in variable $tmpdominio
and then compare these two information to see if the domain already exists in the bank. As I am starting, so far I have this code.
# Pegando o dominio deste email
$emaildoform = $_POST['email'];
$tmpdominio = explode('@', $emaildoform);
# Pegando todos os emails da minha tabela
$dados = mysql_query("SELECT email FROM wp_agencias");
while($arraydeemails = mysql_fetch_array($dados)){
# Eu preciso extrair o domínio de cada e-mail do array ...
# ... depois vou comparar com $tmpdominio para ...
# ...verificar se dominio está presente na base
};
Have you ever tried to set the email field as unique in the bank? you can only have an email with the same domain in your bank?
– Erlon Charles
Have you tried using the in_array()
– Erlon Charles
Instead of bringing all the data from the database, why not use the like in your query to search for email with that domain? If you return any results, it is because the email exists in the database.
– Filipe Moraes
@Filipe is that in another answer of those days, "they taught" him to use this thing of storing db in array unnecessarily. What is spent for nothing in memory, because even in that other one, you could use Mysql’s "save result" if you needed to keep the data. The funny thing about the other question is that the owner of the complicated answer erroneously said that the others were wrong, and even took the Accept :)
– Bacco
@Bacco because, the query should return the smallest possible result and using array is not always the best solution.
– Filipe Moraes