2014-07-19 62 views
-1

我想改變一個基於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> 
+8

對於if($ list ['orderready'] =「是」)和elseif($ list ['orderready'] =「否」),您正在分配'='而不是比較'=​​='。 ' –

+0

換句話說,做'if($ list ['orderready'] ==「是」)'和'elseif($ list ['orderready'] ==「否」)' –

+0

FYI它可能仍然正常工作,但是如你所做的那樣,將表單標籤放在表格元素之間不是有效的HTML。 – faintsignal

回答

1

我會讓my comment爲解決這個問題的答案。

您可以使用一個等號=,而不是兩個爲comparing==爲您的

if ($list['orderready'] = "Yes")elseif ($list['orderready'] = "No")

變化是目前assigning那些:

if ($list['orderready'] == "Yes")elseif ($list['orderready'] == "No")

旁註:只是爲了涵蓋所有的基數,請確保您的列包含YesNo而不是YESNO這應該是一個促成因素;他們是區分大小寫的,至少在我的測試中是這樣。

0

if($list['orderready'] = "Yes")被賦值。它應該是if($list['orderready'] === 'Yes')elseif($list['orderready'] === 'No'),如果你正在做精確的比較。真的,orderready可能應該是在你的數據庫布爾,除非你有一切加密,或無法控制。