Eléphanteau du PHP |
19 Messages
09 avr. 2017, 22:52
voici mon code php si vous pouvez m'aider je vous en serais reconnaissant.
à ce jour quand je change de catégorie, il n'y a pas de modification dans mes box.
je ne vois pas trop comment faire.
//selection
$sporthigh = "SELECT *, max(`id_sport`) FROM `distribution` WHERE `id_user`= $idfonnctuser";
$sporthighresult = mysqli_query($conn, $sporthigh);
if (!$sporthighresult ) {
echo "select maxsport failed: " . mysqli_error($conn);
}
$d = mysqli_fetch_assoc($sporthighresult);
if (!$d ) {
echo "select mr failed: " . mysqli_error($conn);
}
$sportfonctinit = $d['id_sport'];
$categoriefonctioninit = $d['id_categorie'];
//sélectionner la categorie, le sport
if(isset($sportfonctinit)){
$tr="SELECT *, IF(id_type IS NULL, false, true) AS sportactif
FROM type
LEFT OUTER JOIN
(SELECT * FROM `distribution`
WHERE `id_user` = $idfonnctuser AND `id_categorie` = $categoriefonctioninit and `id_sport` = $sportfonctinit ) AS slctHab
ON type.id = slctHab.id_fonction ORDER BY nom ASC";
}else{
$tr = "SELECT *, FALSE as sportactif FROM type ORDER BY nom ASC" ;
}
resulttype = mysqli_query($conn, $tr);
if (!resulttype) {
echo "select type failed: " . mysqli_error($conn);
}
//selection du sport
$trsport = "SELECT * FROM sport ";
$sportname = mysqli_query($conn, $trsport);
if (!$sportname ) {
echo "select sport failed: " . mysqli_error($conn);
}
if (mysqli_num_rows($sportname) == 0) {
echo "erreur aucune sport trouvé!";
}
//selection des categories
$trcategorie = "SELECT * FROM categorie ";
$categorielibelle = mysqli_query($conn, $trcategorie);
if (!$categorielibelle ) {
echo "select categorie failed: " . mysqli_error($conn);
}
if (mysqli_num_rows($categorielibelle) == 0) {
echo "erreur aucune categorie trouvé!";
}
}
if(isset($_POST['type'])) {
//Insérer en bdd les types
if(!empty($_POST['choix']))
{
//echo 'Les valeurs des cases cochées sont : <br />';
$ID_USR = $_GET['id'];
$sportchoisi = $_POST['sport'];
$categoriechoisi = $_POST['categorie'];
$deletedistribution = "DELETE FROM `distribution` WHERE `id_utilisateur`=$ID_USR AND `id_categorie`=$categoriechoisi AND `id_sport`=$sportchoisi" ;
$deletedistributionresult = mysqli_query($conn, $deletedistribution);
if (!$deletedistributionresult ) {
echo "DELETE failed: " . mysqli_error($conn);
}
voici mon code html :
<html>
<label for="">categorie :</label></br>
<select name="categorie" id="categorie">
<?php while($quelcategorie = mysqli_fetch_assoc($categorienom)) {
if (!$quelcategorie ) {
echo "fetch categorie failed: " . mysqli_error($conn);
}
?>
<option
<?php if($quelcategorie['id'] == $categoriefonctioninit)
{
echo "selected=\"selected\"";
} ?>
value=<?php echo $quelcategorie['id'] ?>><?php echo $quelcategorie['id'] . "-" . $quelcategorie['nom'] ?></option>
<?php } ?>
</select>
</td>
<td >
<label for="statut">sport :</label></br>
<select name="sport" id="sport">
<?php while($quelsport = mysqli_fetch_assoc($sportname)) {
if (!$quelsport ) {
echo "select sport failed: " . mysqli_error($conn);
}
?>
<option
<?php if($quelsport['id'] == $sportfonctinit)
{
echo "selected=\"selected\"";
} ?>
value=<?php echo $d['id'] ?>><?php echo $d['id'] . "-" . $d['libelle'] ?></option>
<?php } ?>
</select>
</td>
</tr>
</table>
</div>
</div>
</div>
<!-- tableau -->
<h4 >LISTE DES diiferents types</h4></header>
<thead >
<tr>
<th class="text-center col-sm-4 col-md-4 col-lg-4">nom types</th>
</tr>
</thead>
<tbody>
<!--Afficher la liste des types en bdd-->
<?php while($queltype=mysqli_fetch_assoc(resulttype))
{
if (!$queltype)
{
echo "select type failed: " . mysqli_error($conn);
}
?>
<tr>
<td align='center'><?php if(isset($queltype['nom'])){echo $queltype['id']. "-". $queltype['nom'] ;} ?></td>
<td align='center'><input type="checkbox" id="choix" name="choix[]"
<?php if($queltype['sportactif'] == 1)
{
echo "checked =\"checked\"";
} ?>
value=<?php echo $queltype['id'] ?>></td>
<?php
}
?>
</html>