I need some help with doing some calculations using the values from two different records.

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 20   (RSS)

I need some help with doing some calculations using the values from two different records. The site is for a sea turtle patrol and we have a table of statistics showing how many turtle nests, total turtle eggs, and how many live turtle hatchlings from those eggs. There is a column which displays the value for percentage of live hatchlings. In order to get that value I need to divide live turtle hatchlings by total turtle eggs then multiply * 100. The percentage field is currently calculated and entered manually. I would like to automate this process and have it done using php, as the records are generated/being displayed in the page. (See attached screenshot of the table and data displayed)

Here is the working code which populates the table: 

<?php foreach ($annual_statistics_dataRecords as $record): ?>
<tr>
<td class="boldText" align="center"><?php echo htmlencode($record['data_year']) ?></td>
<td align="center">&nbsp;</td>
<td align="center"><?php echo htmlencode($record['total_number_of_nests']) ?></td>
<td align="center"><?php echo htmlencode($record['total_number_of_eggs']) ?></td>
<td align="center"><?php echo htmlencode($record['total_live_hatchlings']) ?></td>
<td align="center"><?php echo htmlencode($record['percentage_of_live_hatchlings']) ?></td>
</tr>
<?php endforeach ?>

So I need to take ($record['total_live_hatchlings']) and divide that by ($record['total_number_of_eggs']) then multiply by 100 and then display that value instead of the (manually entered) ($record['percentage_of_live_hatchlings'])

Hopefully this all makes sense. Anyone know how to accomplish this

Thanks in advance for any help!

Attachments:

HBTW-Table-Sample.jpg 27K

Thank you so much!! That worked perfectly. You're a lifesaver! I added the round function as well.

Have a great day!

Kevin