Jump to content

if a=b then; not working


simon551

Recommended Posts

hi. this works sometimes, but not others. do you have an idea of what may be causing the if then statement at the end to fail only sometimes. I checked my database and the fields that the two queries draw from are both of type double, length 15 and 2 decimals. I have cases where both sides ($amexAmount and $expAmount) are apparently the same amount i.e. 10942.15, but the function reads them as not equal... but not all the time. Sometimes they are equal and the function reads them as such.

 

<?php 
$totalAmex=0;
$i = 0;
do { 
$totalAmex+=$row_amex['Amount']; 

$i++;
print "<tr class=\"d".($i & 1)."\">";?> 
    <td width="75"><?php echo $row_amex['pDate']; ?></td>
    <td width="400"><?php echo $row_amex['Merchant']; ?></td>
    <td><?php echo DoFormatCurrency($row_amex['Amount'], 2, '.', ',', '$'); ?></td>
  </tr>
<?php } while ($row_amex=mysql_fetch_assoc($rs_amex)); ?>
  <tr>
    <td colspan="2"><h3>Total:</h3></td>
    <td><h3><?php echo DoFormatCurrency($totalAmex , 2, '.', ',', '$'); ?></h3></td>
  </tr>
</table>
<table width="75%">
  <tr>
    <td colspan="3"><h3>Expenses Items to Reconcile:</h3></td>
  </tr>
<?php 
$totalExp=0;
$i = 0;
do { 
$totalExp+=$row_exp['amtUS']; 

$i++;
print "<tr class=\"d".($i & 1)."\">";?> 
    <td width="75"><?php echo $row_exp['fdate']; ?></td>
    <td width="400"><?php echo $row_exp['vendor']; ?></td>
    <td><?php echo DoFormatCurrency($row_exp['amtUS'], 2, '.', ',', '$'); ?></td>
  </tr>
<?php } while ($row_exp=mysql_fetch_assoc($rs_exp)); ?>
  <tr>
    <td colspan="2"><h3>Total:</h3></td>
    <td><h3><?php echo DoFormatCurrency($totalExp , 2, '.', ',', '$'); ?></h3></td>
  </tr>
</table>
<?php if (($totalExp==$totalAmex) || ($override==1))
{ ?>
<h3> Congratulations, the amounts you wish to reconcile are in balance! Continue to complete the reconciling of these charges: </h3> <input name="complete" value="Complete Reconciliation" type="button" onclick="window.location='../postingfiles/amex_recon_final.php'" class="quietButton"/>
<?php
} else { ?>
<h3> You're reconciliation is not in balance. Please return to the <a href="amex_reconciling.php">reconciling page</a>. 
</h3>
<?php } ?>

Link to comment
https://forums.phpfreaks.com/topic/137766-if-ab-then-not-working/
Share on other sites

well the first problem i can see ios that your do-while blocks should be while blocks

so

<?php do { 
$totalAmex+=$row_amex['Amount']; 

$i++;
print "<tr class=\"d".($i & 1)."\">";?> 
    <td width="75"><?php echo $row_amex['pDate']; ?></td>
    <td width="400"><?php echo $row_amex['Merchant']; ?></td>
    <td><?php echo DoFormatCurrency($row_amex['Amount'], 2, '.', ',', '$'); ?></td>
  </tr>
<?php } while ($row_amex=mysql_fetch_assoc($rs_amex)); ?>

should be

<?php while ($row_amex=mysql_fetch_assoc($rs_amex)){
$totalAmex+=$row_amex['Amount']; 

$i++;
print "<tr class=\"d".($i & 1)."\">";?> 
    <td width="75"><?php echo $row_amex['pDate']; ?></td>
    <td width="400"><?php echo $row_amex['Merchant']; ?></td>
    <td><?php echo DoFormatCurrency($row_amex['Amount'], 2, '.', ',', '$'); ?></td>
  </tr>
<?php } ?>

you need to fix the other one to

then try and see

 

Scott.

I don't know why, Scott, but if I use your code, the script doesn't output the first row of the output. For example, old code output is:

2008-10-07  Merchant 1  $388.38

2008-10-07 Merchant 2 $778.32

2008-10-12 Merchant 3 $8.84

total: $1175.54

Changing to your code outputs:

2008-10-07 Merchant 2 $778.32

2008-10-12 Merchant 3 $8.84

total: $787.16

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.