使用MySQLi选择行数组

时间:2016-04-24 20:59:38

标签: php sql

我试图从不同行号的数组中返回结果。现在手动输入mysqli查询中的每个行号。您如何用currentUsers数组的值替换这些值?

$currentUsers = array('1', '3', '7', '10');

while ($row = mysqli_fetch_array ($query))
{   
    $interestValue = ((int) "$row[1]") + 
                     ((int) "$row[3]") + 
                     ((int) "$row[7]") + 
                     ((int) "$row[10]");
    echo "$interestValue";
}

1 个答案:

答案 0 :(得分:0)

while循环内部使用如下数组:

$interestValue = 0;
foreach ( $currentUsers as $i ) {
    $interestValue = $interestValue + (int) $row[$i];
}
echo $interestValue;