我是 php 新手,我把我的代码弄乱了一点。我将不胜感激任何帮助。
$sqltest="SELECT MaId,Amount FROM table1";
$stmttest = sqlsrv_query( $conn, $sqltest);
if( $stmttest === false) {
die( print_r( sqlsrv_errors(), true) );
}
while($test = sqlsrv_fetch_array( $stmttest, SQLSRV_FETCH_ASSOC)){ //fetch array
$combined[] = array($test['MaId']=>$test['Amount']); //pass the first column values as array keys
}
$loop=0;
foreach ($combined as $key => $value) {
foreach ($value as $msid => $msamount) {
while($msid!==25) {
$loop += $msamount;
}
}
}
我试图将 id 不等于 25 的所有金额相加,但我陷入了无限循环。你能解释一下出了什么问题吗?