simon551 Posted December 20, 2008 Share Posted December 20, 2008 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 More sharing options...
ratcateme Posted December 20, 2008 Share Posted December 20, 2008 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. Link to comment https://forums.phpfreaks.com/topic/137766-if-ab-then-not-working/#findComment-720052 Share on other sites More sharing options...
simon551 Posted December 20, 2008 Author Share Posted December 20, 2008 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 Link to comment https://forums.phpfreaks.com/topic/137766-if-ab-then-not-working/#findComment-720060 Share on other sites More sharing options...
ratcateme Posted December 20, 2008 Share Posted December 20, 2008 can you post more of the file up to the query. Scott. Link to comment https://forums.phpfreaks.com/topic/137766-if-ab-then-not-working/#findComment-720203 Share on other sites More sharing options...
simon551 Posted December 20, 2008 Author Share Posted December 20, 2008 hey, I found the problem. I was using a fetch_assoc in the query file. Your code works fine now for output, but I still have the original problem of not totaling. do you still need more info? thanks, -s Link to comment https://forums.phpfreaks.com/topic/137766-if-ab-then-not-working/#findComment-720324 Share on other sites More sharing options...
ratcateme Posted December 20, 2008 Share Posted December 20, 2008 before the if where you check them try to echo them and see what they are if they are the same or not. i can't see any reason for the errors you say are happening Scott. Link to comment https://forums.phpfreaks.com/topic/137766-if-ab-then-not-working/#findComment-720458 Share on other sites More sharing options...
ngreenwood6 Posted December 21, 2008 Share Posted December 21, 2008 You can find the total of the values selected using mysql's built in sum() function. Link to comment https://forums.phpfreaks.com/topic/137766-if-ab-then-not-working/#findComment-720573 Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 If you use mysql sum function, It quicker and more acute, any work that can be done via mysql and not php, should be used it quicker. Link to comment https://forums.phpfreaks.com/topic/137766-if-ab-then-not-working/#findComment-720647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.