Jump to content

Handling Charge


cgigrfx

Recommended Posts

 <?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.

Link to comment
Share on other sites

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 by Psycho
Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>
    

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.