An odd PHP adding issue

Here is a strange one. I have variables that I wish to add together.

[php]
($subtotal + $delprice)
[/php]

For example

If $subtotal = 10 and $delprice = 10.50 When I add them together I get 10.50! Which is strange. What could be the issue. Its the same on all my sums.

Heres the full code:

[php]

 <?php
							$sqlequ="SELECT * FROM job_items WHERE job_id = '$id'";

							$resultequ = mysql_query($sqlequ);


								?>
                                
								<table id="invoiceitems" class="gridtable">
                <thead>
                    <tr>
                    <th><strong>Product ID</strong></th>
                    <th><strong>Description</strong></th>
                    <th><strong>Cost</strong></th>
                    <th><strong>Qty</strong></th>
                    <th><strong>Nett</strong></th>
                    <th><strong>VAT</strong></th>
                    <th><strong>Gross</strong></th>
                    </tr>
                </thead>
               
                <tbody>
                <tr class="noborder">
                    	<td>&nbsp;</td>
                    	<td>&nbsp;</td>
                    	<td>&nbsp;</td>
                    	<td>&nbsp;</td>
                    	<td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                  
                    <?php
						$subtotal = '0'; 
						$vattotal = '0'; 
						$grand = '0'; 
						while($rowequ = mysql_fetch_array($resultequ)){
					?>
                    <tr>                            
						<td><?php echo $rowequ['product_id']; ?></td>
                        
						<td><?php echo $rowequ['description']; ?></td>
                        
						<td><?php echo $site_settings['currency'].$rowequ['unit_price']; ?></td>
                        
						<td><?php echo $rowequ['quantity']; ?></td>
                        
						<td><?php echo $site_settings['currency'].$rowequ['before_vat']; ?></td>
                        
						<td><?php echo $site_settings['currency'].$rowequ['vat']; ?></td>
                        
						<td><?php echo $site_settings['currency'].$rowequ['subtotal']; ?></td>
                        
					</tr>
             		<?php 
							$subtotal = $subtotal + $rowequ['before_vat'];
							$vattotal = $vattotal + $rowequ['vat'];
							$grandtotal = $vattotal + $subtotal;
							
						}
					?>
                </tbody>
                
                <tfoot>
               
                    <tr>
                    	<td>&nbsp;</td>
                    	<td>&nbsp;</td>
                    	<td>&nbsp;</td>
                        <td>&nbsp;</td>
                    	<td>&nbsp;</td>
                    	<td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                    <?php 
						$delprice = $row['delprice']; 
						$delvat = ($delprice * ($site_settings['taxrate']/100));
                    ?>
                    	<td><strong>Delivery</strong></td>
                        <td><?php echo $row['deliver'];?></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td><?php echo $site_settings['currency'].$delprice;?></td>
                        <td><?php echo $site_settings['currency'].number_format($delvat, 2, '.', '');?></td>
                        <td><?php echo $site_settings['currency'].number_format(($delprice + $delvat), 2, '.', '');?></td>
                    </tr>
                    <tr>
                    	<td>&nbsp;</td>
                        <td><strong>Subtotal:</strong></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                   		<td><?php echo $site_settings['currency'].number_format(($subtotal + $delprice), 2, '.', '');?></td>
                    </tr>
                    <tr>
                    	<td>&nbsp;</td>
                        <td><strong>Vat total:</strong></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                   		<td><?php echo $site_settings['currency'].number_format(($vattotal + $delvat), 2, '.', '');?></td>
                    </tr>
                    <tr>
                    	<td>&nbsp;</td>
                        <td><strong>Grand total:</strong></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                   		<td><?php echo $site_settings['currency'].number_format(($grandtotal + $delprice + $delvat), 2, '.', '');?></td>
                    </tr>
                </tfoot>
                
                </table>

[/php]

well i did this

[php]$subtotal =‘10’;
$delprice =‘10.50’;

echo ($subtotal + $delprice);[/php]

and it gave me 20.5

I sorted it it was a odd issue with too many variables and a few missed (). ;D :-[

nah no sad face you figured it out all that matters trial and error

all php coding etc needs trial and error

Sponsor our Newsletter | Privacy Policy | Terms of Service