Désolé l'image de ma base n'est pas passée
Sinon pour code
Controleur
public function edit(){
$table = 'plants';
$pageId=46;
$errors = false;
if(isset($_POST['edit']))
{
if($plant_edit_valid->isValid())
{
$result = $this->Plant->update($_GET['param'], [
'gender_id' => $_POST['plantgender_id'],
]);
}
else
{
$errors = $plant_edit_valid->getErrors();
}
}
$plant = $this->Plant->find_Category($_GET['param']);
$this->loadModel('Plantgender');
$plantgenders = $this->Plantgender->all_orderGender('name');
$this->render('plants/edit', compact('pageId','plant','plantfamilies','plantgenders','planttypes','plantcolors','plantexposures','planthardinesses','plantinflorescences','plantfoliages','plantstatus','errors'));
}
Model
public function all_orderGender($data){
return $this->sql(" SELECT * FROM plantgenders ORDER BY $data ASC ");
}
public function find_Category($id){
return $this->sql("
SELECT plants.*, plantfamilies.familyname ,planttypes.typename,plantcolors.colorname,plantexposures.exposurename,plantstatus.statusname,planthardinesses.name AS hardinessname,plantinflorescences.name AS inflorescencename,plantfoliages.name AS foliagename,plantgenders.name AS gendername
FROM plants
LEFT JOIN plantgenders ON gender_id = plantgenders.id
WHERE plants.id = ?
", [$id],true);
}
public function update($id, $fields){
$sql_parts = [];
$attributes = [];
foreach($fields as $k => $v)
{
$sql_parts[] = "$k = ?";
$attributes[] = $v;
}
$attributes[] = $id;
$sql_part = implode(', ', $sql_parts);
return $this->sql("UPDATE {$this->model} SET $sql_part WHERE id = ?", $attributes, true);
}
View
<form id="form_edit" name="form_edit" method="post" >
<fieldset>
<legend >Modification Plante</legend>
<div class="form-group row">
<label for="gender" class="col-sm-4 col-form-label">Liste Genres</label>
<select class="form-control col-sm-8" name="plantgender_id" id="plantgender_id"><option value="<?=$plant->gender_id;?>"><?=$plant->gendername;?></option>
<?php
foreach($plantgenders as $plantgender): ?>
<option value="<?=$plantgender->id;?>"><?=$plantgender->name;?></option>
<?php endforeach; ?>
</select>
</div>
<button class="btn btn-primary btn-lg" name="edit" id="edit" type="submit" >Modifier</button>
</fieldset>
</form>
Modifié par dudu22 (21 Apr 2022 - 16:53)