我想改變一個基於MySQL結果使用PHP的按鈕,但它只是即使在MySQL值不同時輸出第一個按鈕。我已經做了一些研究,但找不到與這個問題有關的任何事情。PHP回聲基於MySQL結果不起作用
<?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>
對於if($ list ['orderready'] =「是」)和elseif($ list ['orderready'] =「否」),您正在分配'='而不是比較'=='。 ' –
換句話說,做'if($ list ['orderready'] ==「是」)'和'elseif($ list ['orderready'] ==「否」)' –
FYI它可能仍然正常工作,但是如你所做的那樣,將表單標籤放在表格元素之間不是有效的HTML。 – faintsignal