The following code produces an illegal offset error every time the `while()` loops:

> 
> Warning: Illegal string offset 'username' in /Applications/MAMP/htdocs/admin/scripts/email\_owners\_send.php on line 48
> 
> 
> 

I'm trying to set `$name` to be `$email['username']` if `$email['username']` **isn't empty**, and if **is** empty, `$name` should be set to `$email`. `$email` is set by the `while()` statement, from a `mysql_fetch_assoc()`. This is my code at the moment:

```
// print out all the email address recipients
$query = mysql_query("SELECT * FROM ownersemails WHERE deleted=0 LIMIT 5");
$recipients = '';
$total = mysql_num_rows($query);
$num = 0;
while($email = mysql_fetch_assoc($query)) {
    // add to count
    $num++;

    // set email
    $email = $email['email'];

    // set name as username if apparant
    if(!empty($email['username'])) {
        $name = $email;
    }
    else {
        $name = $email['username'];
    }

    // add to recipients string (=. append)
    $recipients .= '{ "email": "'.$email.'", "name": "'.$name.'" }';
    // only add a comma if it isn't the last one
    if($num!=$total) {
        $recipients .=',';
    }
}

```