I making a language loop inside a structure that return the result in radio and i need to return the last select that user selected before inside this foreach ... in this code i get duplicated result the checked one and unchecked one. How can I show the result checked without duplicated ?
<?php
// to select the language that insert in table "x_language" for this user
// the result is 1 in this case
$usuario_id = $this->session->userdata('usuario_id');
$usuario_id = $this->cake->get_current_language_to_user($usuario_id);
// to get all languages from table "y_languages"
$paises = $this->cake->get_paises();
$i = 0;
foreach($paises as $pais){
// here i get to checked the "y_languages" -> "$pais->nome" that have the same result on "x_language"
if($usuario_id['nome'] == $pais->nome){echo "<div class='radio iradio'><label><input type='radio' checked='checked' name='languageselected' value='".$pais->id_pais."'> ".$pais->nome."</label></div>"; }
++$i;
echo "<div class='radio iradio'><label><input type='radio' name='languageselected' value='".$pais->id_pais."'> ".$pais->nome."</label></div>";
if($i%17===0) {
echo "</div></div><div class='col-lg-2'><div class='radio iradio'>";
}
}
?>