Remove a certain value from multiple rows in a table?

0

I'm having trouble creating an algorithm to scan and exclude certain emails from groups of emails.

I have a table where are registered company emails that are displayed on the intranet, with these values are created groups of emails that are stored in another table, what I need to do is the following:

-When I delete an e-mail from the e-mail table, I also perform a search of the e-mail groups that in this column is ([email protected];[email protected];[email protected];[email protected]) and remove from the groups too, I am trying to do this:

$email_i =  $_POST["email-interno"];    
$buscagrupos    =   mysql_query("SELECT emails FROM grupoemail WHERE emails LIKE '%$email_i%'");
        while($lc1  =   mysql_fetch_array($buscagrupos)){
            $g_emails       =   $lc1["emails"];
            $g_emailsE  =   explode(";", $g_emails);
            $key = array_search($email_i, $g_emailsE);
            if($key!==false){
            unset($g_emailsE[$key]);
            $g_emails2  =   implode(";", $g_emailsE);
            $teste2 =   mysql_query("UPDATE grupoemail SET email='$g_emails2' WHERE emails LIKE '%$email_i%'");
            }}

But when I run this, the script is merging all the emails and adding all the existing emails of the lines that had the deleted email and added all of them equally in the same lines, so instead of this occurring:

Grupo 1:
[email protected];[email protected];[email protected]
Grupo2
[email protected];[email protected];[email protected]

Exclude example3 from emails, these groups should be left without it this way:

Grupo 1:
[email protected];[email protected];
Grupo2
[email protected];[email protected]

But no, this is happening:

Grupo 1:
[email protected];[email protected];[email protected]
Grupo2
[email protected];[email protected];[email protected]

Exclude example3 from emails, these groups look like this:

Grupo 1:   [email protected];[email protected];[email protected];[email protected];[email protected]
Grupo 2: [email protected];[email protected];[email protected];[email protected];[email protected]

I know my script is wrong, I just do not know how to adjust = (

    
asked by anonymous 16.10.2015 / 20:29

0 answers