質問

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.

役に立ちましたか?

解決

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

他のヒント

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>';
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top