0

Sir I have these codes

global $mybalance;
$mybalance=0;
$mydrcr='';

$result2 = sqlsrv_query($con,$query) or die ("Error". sqlsrv_errors($con)) ;  
$sno=0;

while($res2 = sqlsrv_fetch_array($result2)) {
echo "<tr>";
$mybalance=($res2['balance']);
echo'Opening Balance='.number_format($mybalance).'<br>';

if($mybalance=0){
$mydrcr='';
}

if($mybalance>0){
$mydrcr='dr';
}

if($mybalance<0){
$mydrcr='cr';
}
echo'Opening Balance='.number_format($mybalance);

The codes
PHP Code:
echo'Opening Balance='.number_format($mybalance);
work fine at line 11 but does not work at line 24

Untitled.png

Please help

Edited by phphp

3
Contributors
2
Replies
17
Views
8 Months
Discussion Span
Last Post by Dani
0
if($mybalance=0){

This is setting the var to 0 not checking it. If you want to check the value use ==

0

As diafol stated, a single equals sign is an assignment and a double equals is a comparison. You are resetting the value to zero inside the If statement and THEN checking to make sure it doesn't equal false.

For example, your while statement has an assignment operator in which you are setting a value and then looping as long as it doesn't resolve to false.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.