如何在回声中将数字加在一起? [关闭]

问题描述 投票:-2回答:3

我在这里有代码

$result = $dbLink->query($sql);         
if($result) {
    while($row = $result->fetch_assoc()) {      
        echo "Assignment Number: {$row['AssNum']}<br/>" ;
        echo "Tutor(90 %) marks: {$row['tutorRecord']}<br/>" ;
        echo "Second(10 %) marks: {$row['secondRecord']}<br/>";
    }
}

我想要这些变量的总和,我从表的行中有两个变量,并且我想在每一行中添加这些变量。变量如下

{$row['tutorRecord']}
{$row['secondRecord']}

我想要total = {$row['tutorRecord']} + {$row['secondRecord']}

这是在isset内部,如果有条件并且我不能在回显内使用添加功能,可以吗?

php html variables echo addition
3个回答
1
投票

那样做加法

$total = $row['tutorRecord'] + $row['secondRecord'] ;  //this if u want have total variable

或者如果您想这样回声

echo "TOTAL = ".$row['tutorRecord'] + $row['secondRecord'] ; // this total just count them 

没有{}


0
投票

使用串联:

echo "Total: ".$row['tutorRecord'] + $row['secondRecord']."<br/>";

-1
投票

否,但是您可以改为这样做: $asd = "Assignment number" . function() ."br>"; echo $asd

只需使function()返回正确的值,然后就可以为表示和计算部分指定代码。

© www.soinside.com 2019 - 2024. All rights reserved.