簡體   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