循环和数组从数据库接收数据

I recovered some information from my database and then I turn into the array using:

<?php $clients = explode(",",$data['comptes']) ; ?>

<?php $clients = explode(",",$data['comptes']) ;
    for ( $i = 0; $i < count( $clients ); $i++ ) { 
 echo '<option value="'.trim($clients[$i]).',">'.trim($clients[$i]).'</option>'; 
} ?>

I would then display all in a selection list.

Before the whole table is not empty, it displays a print_r():

Array (
    [0] => 1566 
    [1] => 1599 
    [2] =>
)

Then for the selection list so I'm doing following code:

but yet it does not return me the last selection list is empty, I do not see where I made ​​my mistake because I have no error messages.

<?php 
    $clients = explode(",",$data['comptes']) ;

    echo '<select id="selectboxname" name="selectboxname">';

    for ( $i = 0; $i < count( $clients ) - 1; $i++ ) 
    { 
        echo '<option value="'.trim($clients[$i]).',">'.trim($clients[$i]).'</option>'; 
    } 

    echo '</select>';
?>

Make sure you have

<select> </select> 

round your options.

I am really guessing, but you probably have an extra comma in $data['comptes']. Try

$clients = explode(",", trim($data['comptes'], ','));