I have a table with two columns of loop results as below:
ORDER_ID | STATUS |
---|---|
ORD001 | YES |
ORD001 | NO |
ORD001 | NO |
ORD001 | YES |
ORD002 | NO |
ORD002 | NO |
what I want to get is to get all rows "ORD001" and check if one of the rows has NO value in STATUS then it will be "False". if all rows are YES then it will be "True".
ORDER_ID | STATUS |
---|---|
ORD001 | YES |
ORD001 | NO |
ORD001 | NO |
ORD001 | YES |
The table above is "FALSE"
ORDER_ID | STATUS |
---|---|
ORD001 | YES |
ORD001 | YES |
ORD001 | YES |
ORD001 | YES |
and if the table is as above then the value is "TRUE".
$query02 = "SELECT ORDER_UID, STATUS FROM order_product WHERE ORDER_UID = '".$data['ordercode']."'";
$getdata = mysqli_query($conn, $query02);
while($row = mysqli_fetch_array($getdata)){
//Update Transaction is Completed
if($row['STATUS'] == "YES"){
$query05 = "UPDATE order_transaction SET ORDER_STATUS = 'TRUE' WHERE ORDER_UID = '".$row['ORDER_UID']."'";
$sql05 = mysqli_query($conn, $query05) or die (mysqli_error($conn));
}
}
My code successfully updated to "TRUE" even though ORD001 had one of the values ’NO’.
can you help me to understand how this works?
and sorry for my english to explain this.
2
Answers
Total shot in the dark. I’m not a PHP expert by any means. But is there a misplaced parenthesis by chance?
This line:
Should it be:
Otherwise, depending on how PHP parses, I could imagine the remaining lines running simply because
$row['STATUS']
evaluates totrue
.Anyway, like I said, total shot in the dark. Your mileage may vary.
This will return YES only if all rows have a status of YES: