php值乘以表的行数

时间:2019-04-12 21:39:23

标签: php

您好,盖伊即时通讯(雨)我是编程(php)的新手。我想对数据库中的值求和并将其乘以html(php form table)中具有相同id的行,这很令人困惑,因此请给出输出。

我得到的是

A. Sample 1
 1. 100 = 200
 2. 100 = 200

B. Sample 2
 1. 100 = 200
 2. 100 = 200
 3. 100 = 200

B. Sample 3
 1. 100 = 200
 2. 100 = 200
 3. 100 = 200
 4. 100 = 200

我想得到的是

B. Sample 2
 1. 100 = 300
 2. 100 = 300
 3. 100 = 300

C. Sample 3
 1. 100 = 400
 2. 100 = 400
 3. 100 = 400
 4. 100 = 400

表格

<?php echo $row["points"];?>
<?php $s=$row["points"]; +  $b=$row["points"]; echo $s + $b;?>

2 个答案:

答案 0 :(得分:1)

我不是100%肯定这是您要寻找的东西,但我最大的猜测是:

示例:

imageItem

输出:

<?php
$samples = array(
    array(100, 150),
    array(100, 150, 200),
    array(100, 150, 200, 250)
);

$i = 1;
foreach($samples as $sample)
{
    $rows = sizeof($sample);
    echo "Sample $i: <br>";

    $j = 1;
    foreach($sample as $row)
    {
        $val = $row * $rows;
        echo "$j. $row = $val <br>";
        $j++;
    }
    $i++;
    echo "<br>";
}
?>

答案 1 :(得分:0)

我做到了

<?php
        $samples = array(
        array($row["points"]),
        );
        foreach($samples as $sample)
        {
        $row["points"];
        $rows = sizeof($sample);
        foreach($sample as $row)
        {
        $val = $row * $rows;
        }   
        }
        ?>  

现在我需要行来计算数据库生成的表行 例如$ val = $ row * value(表行数)