elabuwa Posted December 10, 2009 Share Posted December 10, 2009 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 == { $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); } } } 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: can you pleaase help me out. :shrug: :shrug:im kinda stuck. lol. Link to comment https://forums.phpfreaks.com/topic/184589-wierd-if-else-problem/ Share on other sites More sharing options...
blueman378 Posted December 10, 2009 Share Posted December 10, 2009 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 https://forums.phpfreaks.com/topic/184589-wierd-if-else-problem/#findComment-974645 Share on other sites More sharing options...
elabuwa Posted December 10, 2009 Author Share Posted December 10, 2009 crapola. ma bad. will keep it in mind. Can anyone tell me why php is playin around wimme? Link to comment https://forums.phpfreaks.com/topic/184589-wierd-if-else-problem/#findComment-974810 Share on other sites More sharing options...
Adam Posted December 10, 2009 Share Posted December 10, 2009 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 https://forums.phpfreaks.com/topic/184589-wierd-if-else-problem/#findComment-974818 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.