[英]Selecting an array of rows using MySQLi
I'm trying to return results from an array of varying row numbers. 我正在尝试从不同的行号数组返回结果。 Right now each row number in mysqli query is manually entered. 现在,手动输入mysqli查询中的每个行号。 How would you replace these values with the values of the currentUsers
array? 您将如何用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";
}
Inside the while
loop use the array like this: 在while
循环内,使用如下数组:
$interestValue = 0;
foreach ( $currentUsers as $i ) {
$interestValue = $interestValue + (int) $row[$i];
}
echo $interestValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.