Buy Now
Sign in

Simple php formula to modify a value inside a repeater area

bensonley , January 09 at 14:12
Answered
b
bensonley

Hi Im trying to create a value from another value inside a repeater area. Here's an example:

I want to work out weekly rate when given monthly - simple multiplication like this inside the repeater area:

				$weekly = {var:repeater_view.Model.field}*0.23; 
print ($weekly);


I'm having problems working out how to get the field value in php, so replacing the content within the {} I just get 0 each time.

Ive tried
				$weekly = $this->data['fieldname']  * 0.23; 
print ($weekly);


but doesnt find it, just gives 0 each time.

Any ideas?

Thanks

Ben

e
emmexx

bensonley:

Hi Im trying to create a value from another value inside a repeater area. Here's an example:

I want to work out weekly rate when given monthly - simple multiplication like this inside the repeater area:



Your syntax is wrong:

				$this->data('fieldname')
				


Variable shortcodes
Request data paragraphs, yellow/orange box.

Bye
maxx

b
bensonley

Hi Maxx,

I made changes using the correct syntax, bust still get 0 value printed. Is it because it is inside a repeater that is doesn't work or do i need to change the syntax slightly?

This is how i have the repeater setup - its used for creating tables inside a tcpdf:

Data provider : {var:read_properties} - this is workign fine as all data below appears except for the php which results in 0

Content:

				<tr nobr="true">
<td width="15%">{var:repeater_sirva.row.Prop.time}</td>
<td width="15%">{var:repeater_sirva.row.Prop.estate_agent}<br/>{var:repeater_sirva.row.Prop.agent_contact} - {var:repeater_sirva.row.Prop.agent_phone}<br/>{var:repeater_sirva.row.Prop.agent_email}</td>
<td width="20%">{var:repeater_sirva.row.Prop.address}</td>
<td width="15%"><a href="{var:repeater_sirva.row.Prop.link}">Link to Property</a></td>
<td width="10%">£{var:repeater_sirva.row.Prop.cost} PCM <br/>
<?php
$weekly = $this->data('cost') * 0.23;
print ($weekly);
?> PW
</td>
<td width="25%">{var:repeater_sirva.row.Prop.description}</td>
</tr>


Header:
				<table class="table"  cellpadding="10" border="1"  cellpadding="5" >
<thead>
<tr><th width="15%"><h3>Time</h3></th><th width="15%"><h3 >Agent</h3></th><th width="20%"><h3>Property Address</h3></th><th width="15%"><h3>Property Details</h3></th><th width="10%"><h3>Price</h3></th><th width="25%"><h3>Additional Information</h3></th></tr>
</thead>
<tbody>


Footer:
				</tbody></table>
				

e
emmexx

bensonley:

I made changes using the correct syntax, bust still get 0 value printed. Is it because it is inside a repeater that is doesn't work or do i need to change the syntax slightly?

This is how i have the repeater setup - its used for creating tables inside a tcpdf:

Data provider : {var:read_properties} - this is workign fine as all data below appears except for the php which results in 0


I suppose that cost is not a request data value but some value in the data provider of the repeater.
To access the values of a var you use a different syntax:
				$this->get('repeater_sirva.row.Prop.cost')
				


I think you should read the chronoforms v6 manual that you can find in the Download section.

bye
maxx

b
bensonley

Many thanks Maxx - a great help!

I've used this code in the end, as i realised some users liked to add a comma in the value, but i was expecting an integer so the number formatting needed changing first! I did try what you wrote above before but couldnt work out why i was just getting 0.23 or 0. So here's what i came up with:

				$monthly = $this->get('repeater_sirva.row.Prop.cost') ; 
$monthly = preg_replace("/[^0-9\.]/", "", $monthly);
echo '£' . number_format($monthly) . ' PCM';
echo '<br/>';
$factor = '0.23';
$pcw = $monthly * $factor;
echo '£' . number_format($pcw) . ' PW';