cgigrfx Posted April 9, 2013 Share Posted April 9, 2013 <?php $arr_val1 = array();$arr_val2 = array(); while($rows = mysql_fetch_assoc($rs_prd)) {$arr_val1[] = $rows['quantity'];$arr_val2[] = $rows['amount']; $is_handeling=1;?> We have a piece of code that is supposed to add a "handling" charge when someone purchases a product. For every product they purchase, another handling charge occurs...so far it will only show for (1) handling charge even if there is (4) products. Any help would be greatly appreciated. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
trq Posted April 9, 2013 Share Posted April 9, 2013 Your code makes little sense thanks to nameless variables. Care to elaborate? Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 9, 2013 Share Posted April 9, 2013 (edited) Not nearly enough information to provide any help. What I see is two arrays that are created (given the extraordinarily intuitive names of $arr_val1 and $arr_val2) which are populated with the 'quantity' and 'amount' of each record from an apparent database query. There is also a "flag" variable, $is_handeling, which is set to 1 if there were any records in the result set. What happens after that is impossible to determine. Perhaps the code to actually calculate the handling isn't checking the contents or number of items in the array and is only checking the $is_handeling variable. Edited April 9, 2013 by Psycho Quote Link to comment Share on other sites More sharing options...
cgigrfx Posted April 9, 2013 Author Share Posted April 9, 2013 This is more of the code...Psycho, I believe you are correct. To be able to issue a handling charge per product in the cart would require completely different code than what is here, correct? It's not as simple as changing one line? <fieldset style="width:700px; margin:auto;border:#FFF 1px solid;"> <legend style="font-size:14px; font-weight:bold;" >Your Product Information</legend> <table width="88%" border="0" align="center" cellpadding="0" cellspacing="2"> <tr> <td align="left" width="250"><strong>Product/Service Name</strong></td> <td align="right" width="45"><strong>Quantity</strong></td> <td align="right" width="100"><strong>Price</strong></td> </tr> <tr height="2px" bgcolor="#fff"> <td align="left"></td> <td align="right"></td> <td align="right"></td> </tr> <?php $arr_val1 = array();$arr_val2 = array(); while($rows = mysql_fetch_assoc($rs_prd)) {$arr_val1[] = $rows['quantity'];$arr_val2[] = $rows['amount']; $is_handeling=1;?> <tr> <td align="left"> <?php echo $rows['product'];?> ( Product )</td> <td align="right"> <?php echo $rows['quantity'];?></td> <td align="right"> $<?php echo number_format($rows['amount'],2);?></td> </tr> <?php } while($rows1 = mysql_fetch_assoc($rs_prd1)) {$arr_val1[] = $rows1['quantity'];$arr_val2[] = $rows1['amount'];?> <tr> <td align="left"> <?php echo $rows1['service'];?> ( Service )</td> <td align="right"> <?php echo $rows1['quantity'];?></td> <td align="right"> $<?php echo number_format($rows1['amount'],2);?></td> </tr> <?php }?> <? if($is_handeling==1){ $arr_val2[] ="17.97";?> <tr> <td align="left"> Handling Charges ( Extra )</td> <td align="right"> </td> <td align="right"> $17.97 </td> </tr> <? }?> <tr height="2px" bgcolor="#fff"> <td align="left"></td> <td align="right"></td> <td align="right"></td> </tr> <tr> <td align="left"> <strong>Total</strong></td> <td align="right"> <strong><?php echo array_sum($arr_val1);?></strong></td> <td align="right"> <strong>$<?php echo number_format(array_sum($arr_val2),2);?></strong></td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 10, 2013 Share Posted April 10, 2013 You'd have to change two lines. Quote Link to comment Share on other sites More sharing options...
cgigrfx Posted April 10, 2013 Author Share Posted April 10, 2013 After doing research, I tried this...changes are in red, but still it does not come up correctly? I can't seem to figure out what I am doing wrong. Any help is appreciated in advance. <fieldset style="width:700px; margin:auto;border:#FFF 1px solid;"> <legend style="font-size:14px; font-weight:bold;" >Your Product Information</legend> <table width="88%" border="0" align="center" cellpadding="0" cellspacing="2"> <tr> <td align="left" width="250"><strong>Product/Service Name</strong></td> <td align="right" width="45"><strong>Quantity</strong></td> <td align="right" width="100"><strong>Price</strong></td> </tr> <tr height="2px" bgcolor="#fff"> <td align="left"></td> <td align="right"></td> <td align="right"></td> </tr> <?php $arr_val1 = array();$arr_val2 = array(); while($rows = mysql_fetch_assoc($rs_prd)) {$arr_val1[] = $rows['quantity'];$arr_val2[] = $rows['amount']; $is_handeling=$i + 1;?> <tr> <td align="left"> <?php echo $rows['product'];?> ( Product )</td> <td align="right"> <?php echo $rows['quantity'];?></td> <td align="right"> $<?php echo number_format($rows['amount'],2);?></td> </tr> <?php } while($rows1 = mysql_fetch_assoc($rs_prd1)) {$arr_val1[] = $rows1['quantity'];$arr_val2[] = $rows1['amount'];?> <tr> <td align="left"> <?php echo $rows1['service'];?> ( Service )</td> <td align="right"> <?php echo $rows1['quantity'];?></td> <td align="right"> $<?php echo number_format($rows1['amount'],2);?></td> </tr> <?php }?> <? if($is_handeling==$i + 1){ $arr_val2[] ="17.97";?> <tr> <td align="left"> Handling Charges ( Extra )</td> <td align="right"> </td> <td align="right"> $17.97 </td> </tr> <? }?> <tr height="2px" bgcolor="#fff"> <td align="left"></td> <td align="right"></td> <td align="right"></td> </tr> <tr> <td align="left"> <strong>Total</strong></td> <td align="right"> <strong><?php echo array_sum($arr_val1);?></strong></td> <td align="right"> <strong>$<?php echo number_format(array_sum($arr_val2),2);?></strong></td> </tr> </table> </fieldset> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.