Pregunta

i have the following code:

foreach($result->response->Results as $entry) { 

    echo '<tr class="'. $entry->EmailAddress.'">';      
    echo '<td>'. $entry->EmailAddress.'</td>';

    echo '<td></td><td>';



foreach($unsubscribers->response->Results as $entry2) { 


echo $entry2->EmailAddress; }

    echo '</td><td></td>';
    echo '<td></td>';
    echo '<td></td>';

    echo '</tr>';

}

the first loop pulls in a list of recipients email address's via the campaign monitor api, the second loop pulls in the people who have unsubscribed.

My problem is, there are 100 subscribers that get pulled in, and currently 1 of them have unsubscribed. That 1 unsubscriber gets looped through 100 times, and obviously gets displayed.

How would i go about adapting the above to make it so the unsubscriber doesn't show however many times there are subscribers.

¿Fue útil?

Solución

Do you mean something like this?

// Add the unsubscribers to an array
$unsubs = array();
foreach($unsubscribers->response->Results as $entry2) {
    $unsubs[] = $entry2->EmailAddress;
}

// Loop through the subscribers
foreach($result->response->Results as $entry) { 

    echo '<tr class="'. $entry->EmailAddress.'">';      
    echo '<td>'. $entry->EmailAddress.'</td>';
    echo '<td></td><td>';

    // If the subscriber is in our unsubscriber array, output the email again
    if(in_array($entry->EmailAddress, $unsubs)) { 
        echo $entry->EmailAddress;
    }

    echo '</td><td></td>';
    echo '<td></td>';
    echo '<td></td>';
    echo '</tr>';

}

It will only output the email in the second column if that subscriber is also in the unsubscribers array

Otros consejos

check this codes its probably work for your way.

foreach($result->response->Results as $entry){ 

    echo '<tr class="'. $entry->EmailAddress.'">';      
    echo '<td>'. $entry->EmailAddress.'</td>';
    echo '</tr>';
}

foreach($unsubscribers->response->Results as $entry2){ 
    echo '<tr class="'. $entry2->EmailAddress.'">';      
    echo '<td>'. $entry2->EmailAddress.'</td>';
    echo '</tr>';
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top