in your case $x
is an array. so you can't compare array to a string like this
if ($x == '1')
you need to use the index to compare
if ($x['status'] == '1')
Question
Hello I'm new to PHP.
So I have this query here that checks if Order Total
's status
is set to 1 or 0 in the database
$chk_dscnt=mysql_query("SELECT * FROM `discount` WHERE `discount_type` = 'Order Total' ");
while ($x=mysql_fetch_array($chk_dscnt)) {
echo $x['status'];
}
(I already have a function to change the status to 1 or 0)
.
I would like to do a discount on the $grand_total
if the status
is 1 and display the normal $grand_total
if the status is 0. But even if I set the status
to 1 or 0 it always performs the elseif statement
and displays the undiscounted price
or the normal price.
Is there any logical or syntax error ?? need you help guys :)
if ($x == '1')
{
$subt = 0;
$discounted_price= $grand_total - ($grand_total*(5/100) );
$subt= $subt + $discounted_price;
echo '<input type=text name=total value='.$subt.'>';
}
else if($x == '0'){
$subt =$grand_total; ;
echo '<input type=text name=total value='.$subt.'>';
}
Solution
in your case $x
is an array. so you can't compare array to a string like this
if ($x == '1')
you need to use the index to compare
if ($x['status'] == '1')