I would use a single query and some array functions. This is off the
cuff (untested) but should work as far as I can tell. Might do it
slightly differently if you need the id of the User as well to do
further processing, but you should be able to figure out the rest
yourself.
$input_usernames = split(",", $data['Mail']['receiver_username']);
$found_usernames = $this->User->findAll( array('User.username' =>
$input_usernames), 'User.field' );
$found_usernames = Set::extract($found_usernames,
'{n}.User.username');
$orphan_usernames = array_diff($input_usernames, $found_usernames);
pr($orphan_usernames); // the list of usernames that were not found
Cheers,
Adam
On Dec 5, 1:15 pm, butangphp <[EMAIL PROTECTED]> wrote:
> Basically, I am writing a mailing class
>
> $comma = ",";
> if (strchr($data['Mail']['receiver_username'], $comma))
> {
> //remove the commas and create and array of usernames
> $email_list = split(",", $data['Mail']['receiver_username']);
>
> foreach ($email_list as $receivers)
> {
> $receivers_id =
> $this->User->getUserIdByUsername($receivers);
> $conditions = 'User.id = "'.$receivers_id.'"';
> $receivers = $this->User->field('username',
> $conditions);
>
> if ($receivers == 'FALSE')
> {
> //if one of the usernames is false, remove it and
> continue with the
> rest
> }
>
> }
>
> If theres a comma (and hence more than one name listed) I split the
> string and create an array.
> I need a function in order to weed out usernames that are not in the
> database. Any suggestions??
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---