bonjour,
je dois gérer un service habillement
en gros j'ai une table catégorie (pantalon, veste, ...)
une table agent
une table habillement qui a l'id de la catégorie et du personnel associé avec deux champs (taille et numéro) vue que chaque catégorie aura une taille et un numero.

Je suis bloque dans mon formulaire d'ajout et de modif des tailles par agent.
Le code ci dessous fonctionne car j'ai mis en dur mes catégories $hab1 $hab2 ... $hab5, mais je voudrais faire ça automatiquement
J'ai réussi dans mon formulaire
[code]
foreach($cat as $k => $v){
echo '<div class="form-group">';
echo '<label>'.$v.'</label><br>';
echo $f->input('thab'.$k.'','Taille',array('class'=>'form-control','placeholder' => 'Taille'));
echo $f->input('nhab'.$k.'','Numéro',array('class'=>'form-control','placeholder' => 'Numéro'));
echo '</div>';
}
[/code]

Voici le code complet
je voudrais faire une boucle des $hab et fusionner les array
[code]
$agent = new Agent();
$id = intval($_GET['id']);
$agent->verifId($id);
$habillement = new Habillement();
$cat = $habillement->ListCatHab();
$f = new Formulaire();

    $hab1 = $habillement->vueHabM($id,1);
    $hab2 = $habillement->vueHabM($id,2);
    $hab3 = $habillement->vueHabM($id,3);
    $hab4 = $habillement->vueHabM($id,4);
    $hab5 = $habillement->vueHabM($id,5);

    $hab = array_merge($hab1,$hab2,$hab3,$hab4,$hab5);

print_r($hab);
$f->set($hab);

//traitement
if(isset($_POST['data'])){}
//formulaire
echo '<div class="col-lg-6">';
echo $f->formStart(array('method' => 'POST', 'action' => 'index.php?admaction=Habillementmodif&id='.$id.''));
foreach($cat as $k => $v){
echo '<div class="form-group">';
echo '<label>'.$v.'</label><br>';
echo $f->input('thab'.$k.'','Taille',array('class'=>'form-control','placeholder' => 'Taille'));
echo $f->input('nhab'.$k.'','Numéro',array('class'=>'form-control','placeholder' => 'Numéro'));
echo '</div>';
}

echo'<button type="submit" class="btn btn-default">Modifier</button>';
echo $f->formEnd();
echo '</div>';

}

[/code]

ici mes fonctions
[code]
public function ListCatHab(){
$r = 'SELECT * FROM cat_hab ORDER BY id_cat_hab ASC';
$req = mysql_query($r) or die('Erreur SQL !<br>'.$r.'<br>'.mysql_error());
$rows = array();
while ($row = mysql_fetch_assoc($req)) {
$rows[$row['id_cat_hab']] = $row['cat_hab'];
}
return $rows;
}

public function vueHabM($id,$i){
$r = "SELECT hab.n_hab, hab.t_hab
FROM hab
JOIN cat_hab ON cat_hab.id_cat_hab = hab.id_cat_hab
WHERE hab.id_personnel = '$id' AND hab.id_cat_hab = '$i'
";
$req = mysql_query($r) or die('Erreur SQL !<br>'.$r.'<br>'.mysql_error());
$row = mysql_fetch_array($req);
$rows[] = array(
'nhab'.$i.'' => $row['n_hab'],
'thab'.$i.'' => $row['t_hab'],
);
return $rows;
}
[/code]

Aucune réponse