Jump to content

Wierd if else problem


elabuwa

Recommended Posts

Hi guys,

 

this probably aint wierd for you, but it seems like php is playin up to me. may b i missed something. so i'm kinda needing another set or may more sets of eyes. lol.

 

this is the code.

 

while($row = mysql_fetch_array($result)){

$debit = $row['debit'];

$credit = $row['credit'];

$acnum = $row['acnum'];

$query1 = "SELECT cbal FROM accounts WHERE acnum = '$acnum'";

$res = mysql_query($query1);

$balancenum=mysql_num_rows($res);

while($row1 = mysql_fetch_array($res)){

$cbal = $row1['cbal'];

}

If (is_numeric($debit)){

$actype = substr($acnum,0,1);

settype($actype, "integer");

echo $actype;

echo "<br>";

echo gettype($actype);

echo "<br>";

If ($actype == 1 || $actype == 5 || $actype == 6 || $actype == 8){

$cbal = $cbal - $debit;

$sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";

echo "2" . $sql2;

echo "<br>";

mysql_query($sql2);

} else {

$cbal = $cbal + $debit;

$sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";

echo "2". $sql2;

echo "<br>";

mysql_query($sql2);

}

}

If (is_numeric($credit)){

$actype = substr($acnum,0,1);

settype($actype, "integer");

echo $actype;

echo "<br>";

echo gettype($actype);

echo "<br>";

If ($actype == 1 || $actype == 5 || $actype == 6 || $actype == 8){

$cbal = $cbal + $credit;

$sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";

echo $sql;

echo "<br>";

mysql_query($sql);

} else {

$cbal = $cbal - $credit;

$sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";

echo $sql;

echo "<br>";

mysql_query($sql);

}

}

}

 

The wierd thing about the above code is the entire if statement is carried out including the else part.

For example if $actype == 5 it does the stuff that is to be done when the value is 5, AND the stuff to be done in the ELSE section is also carried out. :wtf: :wtf: :wtf: :wtf:

 

can you pleaase help me out.  :shrug: :shrug: :shrug: :shrug:im kinda stuck. lol.  :D

Link to comment
Share on other sites

Hi mate,

pleased use


tags,

 

while($row = mysql_fetch_array($result)){
   $debit = $row['debit'];
   $credit = $row['credit'];
   $acnum = $row['acnum'];
   $query1 = "SELECT cbal FROM accounts WHERE acnum = '$acnum'";
   $res = mysql_query($query1);
   $balancenum=mysql_num_rows($res);
   while($row1 = mysql_fetch_array($res)){
      $cbal = $row1['cbal'];
   }
   If (is_numeric($debit)){
      $actype = substr($acnum,0,1);
      settype($actype, "integer");
      echo $actype;
      echo "<br>";
      echo gettype($actype);
      echo "<br>";
      If ($actype == 1 || $actype == 5 || $actype == 6 || $actype == {
         $cbal = $cbal - $debit;
         $sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo "2" . $sql2;
         echo "<br>";
         mysql_query($sql2);
      } else {
         $cbal = $cbal + $debit;
         $sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo "2". $sql2;
                  echo "<br>";
         mysql_query($sql2);
      }
   }
   If (is_numeric($credit)){
      $actype = substr($acnum,0,1);
      settype($actype, "integer");
      echo $actype;
      echo "<br>";
      echo gettype($actype);
      echo "<br>";
      If ($actype == 1 || $actype == 5 || $actype == 6 || $actype == {
         $cbal = $cbal + $credit;
         $sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo $sql;
         echo "<br>";
         mysql_query($sql);
      } else {
         $cbal = $cbal - $credit;
         $sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo $sql;
                  echo "<br>";
         mysql_query($sql);
      }
   }
}

Link to comment
Share on other sites

Odd. Can't see a reason why it would. Is it definitely doing both? Try adding in some random echo's to check for sure..

 

while($row = mysql_fetch_array($result)){
   $debit = $row['debit'];
   $credit = $row['credit'];
   $acnum = $row['acnum'];
   $query1 = "SELECT cbal FROM accounts WHERE acnum = '$acnum'";
   $res = mysql_query($query1);
   $balancenum=mysql_num_rows($res);
   while($row1 = mysql_fetch_array($res)){
      $cbal = $row1['cbal'];
   }
   If (is_numeric($debit)){
      $actype = substr($acnum,0,1);
      settype($actype, "integer");
      echo $actype;
      echo "<br>";
      echo gettype($actype);
      echo "<br>";
      If ($actype == 1 || $actype == 5 || $actype == 6 || $actype ==  {
         echo 'foo';
         $cbal = $cbal - $debit;
         $sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo "2" . $sql2;
         echo "<br>";
         mysql_query($sql2);
      } else {
         echo 'bar';
         $cbal = $cbal + $debit;
         $sql2="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo "2". $sql2;
                  echo "<br>";
         mysql_query($sql2);
      }
   }
   If (is_numeric($credit)){
      $actype = substr($acnum,0,1);
      settype($actype, "integer");
      echo $actype;
      echo "<br>";
      echo gettype($actype);
      echo "<br>";
      If ($actype == 1 || $actype == 5 || $actype == 6 || $actype ==  {
         $cbal = $cbal + $credit;
         $sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo $sql;
         echo "<br>";
         mysql_query($sql);
      } else {
         $cbal = $cbal - $credit;
         $sql="UPDATE accounts SET cbal = '$cbal' WHERE acnum = '$acnum'";
         echo $sql;
                  echo "<br>";
         mysql_query($sql);
      }
   }
}

 

(note the 'foo' / 'bar' echos)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.