J'essaie de changer un bouton basé sur un résultat MySQL en utilisant PHP mais il sort seulement le premier bouton même si la valeur de MySQL est différente. J'ai fait des recherches mais je n'ai rien trouvé de vraiment lié à ce problème.php echo basé sur le résultat de MySQL ne fonctionne pas
<?php
$result = $db_server->query("SELECT * FROM orderinfo ORDER BY orderid"); ?>
</style>
<div class="container">
<table class="table table-condensed">
<thead>
<tr>
<th>Order ID</th>
<th>Name</th>
<th>Item</th>
<th>Paid</th>
<th>Ready</th>
<th>Done</th>
</tr>
</thead>
<?php
// LOOP THROUGH LIST OF ORDERS
while ($list = mysqli_fetch_assoc($result)) { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="id" value="<?php echo $list['orderid']; ?>">
<input type="hidden" name="orderready1" value="2">
<tbody>
<tr>
<td><?php echo $list['orderid']; ?></td>
<td><?php echo $list['ordername']; ?></td>
<td><?php echo $list['orderitem']; ?></td>
<td><?php echo $list['orderpaid']; ?></td>
<td><?php echo $list['orderready']; ?></td>
<td><?php
if ($list['orderready'] = "Yes") {
echo "<button type='submit' class='btn btn-success' disabled><i class='glyphicon glyphicon-star'></i></button>";
}elseif ($list['orderready'] = "No") {
echo "<button type='submit' class='btn btn-danger' name='starorder'><i class='glyphicon glyphicon-ok'></i></button>";
}
?>
</td>
</tr>
</tbody>
</form>
<?php
} // END WHILE
?>
</table>
Vous attribuez '=' au lieu de comparer '==' pour 'if ($ list ['orderready'] =" Yes ")' et 'elseif ($ list ['orderready'] =" Non ") ' –
En d'autres termes, faites' if ($ list ['orderready'] == "Oui") 'et' elseif ($ list ['orderready'] == "Non") ' –
FYI Cela peut encore fonctionner correctement, mais ce n'est pas un code HTML valide pour placer la balise de formulaire entre les éléments de la table comme vous l'avez fait. – faintsignal