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

Recommended Answers

All 2 Replies

Member Avatar for diafol
if($mybalance=0){

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.