在echo中添加变量?

时间:2012-12-17 20:21:54

标签: php html mysql mysqli

我这里有代码

$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']}

这是在ifset里面如果条件和我不能在echo里面使用add函数我可以吗??

非常感谢

3 个答案:

答案 0 :(得分:1)

像这样添加

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

或者如果你想像那样回应

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

没有{}

答案 1 :(得分:0)

使用连接:

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

答案 2 :(得分:-1)

不,但你可以这样做:
$asd = "Assignment number" . function() ."br>";
echo $asd

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