繁体   English   中英

使用MySQLi选择行数组

[英]Selecting an array of rows using MySQLi

我正在尝试从不同的行号数组返回结果。 现在,手动输入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";
}

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM