通过Javascript和&添加数字值PHP

时间:2012-10-16 16:29:01

标签: php javascript html

基本上我试图将值加在一起。

我的下面有一个正在回显数字值的ul:

<ul class="TCE">
<li><span>Average drink cost</span>&nbsp;&nbsp;<?php echo the_field('average_drink_price'); ?></li>
<li><span>Average drinks spenditure per night</span>&nbsp;&nbsp;<?php echo the_field('average_drinks_spenditure_per_night'); ?></li>
<li><span>Average drinks spenditure for the year</span>&nbsp;&nbsp;<!-- JAVA BIT --></li>
<li><span>Average drinks spenditure for 3 years</span>&nbsp;&nbsp; <!-- JAVA BIT --></li>
</ul>

我希望第三个li获得第二个li的值,然后将该值乘以28。

然后我希望第四个li获得第三个li的值并将其乘以3.

所以它有点像这样:

li-2 x 28 = li-3 li-3 x 3 = li-4

如果这有道理? li1和li2的值将通过该PHP字段生成,对此有任何帮助,因为我不知道从哪里开始?

更新了PHP测试:

<?php
var_dump(the_field('average_drinks_spenditure_per_night')); 
$li2 = the_field('average_drinks_spenditure_per_night');
$li3 = ($li2 * 28) * 2.1;
$li4 = $li3 * 3;
?>

<ul class="TCE">
<li><span>Average drink cost</span>&nbsp;&nbsp;<?php echo the_field('average_drink_price'); ?></li>
<li><span>Average drinks spenditure per night</span>&nbsp;&nbsp;<?php echo $li2; ?></li>
<li><span>Average drinks spenditure for the year</span>&nbsp;&nbsp;<?php echo $li3;?><!-- JAVA BIT --></li>
<li><span>Average drinks spenditure for 3 years</span>&nbsp;&nbsp; <?php echo $li4;?><!-- JAVA BIT --></li>
</ul>

2 个答案:

答案 0 :(得分:0)

TRY

<?php 
$li2 = 1;
if(is_numeric(trim(the_field('average_drinks_spenditure_per_night'))))
 $li2 = trim(the_field('average_drinks_spenditure_per_night'));
$li3 = $li2 * 28;
$li4 = $li3 * 3;

?>

<ul class="TCE">
<li><span>Average drink cost</span>&nbsp;&nbsp;<?php echo   the_field('average_drink_price'); ?></li>
<li><span>Average drinks spenditure per night</span>&nbsp;&nbsp;<?php echo $li2; ?></li>
<li><span>Average drinks spenditure for the year</span>&nbsp;&nbsp;<?php  echo $li3;?><!-- JAVA BIT --></li>
<li><span>Average drinks spenditure for 3 years</span>&nbsp;&nbsp; <!-- JAVA BIT --></li>
</ul>

答案 1 :(得分:0)

你能做到吗? JavaScript来自哪里?

<?php
    $perNight = the_field('average_drinks_spenditure_per_night');
    $perYear = $perNight * 365;
    $per3Years = $perYear * 3;
?>    

<ul class="TCE">
    <li><span>Average drink cost</span>&nbsp;&nbsp;<?php echo the_field('average_drink_price'); ?></li>
    <li><span>Average drinks spenditure per night</span>&nbsp;&nbsp;<?php echo $perNight; ?></li>
    <li><span>Average drinks spenditure for the year</span>&nbsp;&nbsp;<?php echo $perYear; ?></li>
    <li><span>Average drinks spenditure for 3 years</span>&nbsp;&nbsp;<?php echo $per3Years; ?></li>
</ul>