解釋一下好了
while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC ) ){
//取出收銀員名字放到 name
$name=$row['salesname'];
//$$name 的意思是 把 $name 宣告成變數 =0 isset 是如果變數存在
if(!isset($$name)){
$$name=0;
}
//++ 應該就不用說了吧
$$name++;
}
這樣可以算出每個人出現的次數
不好意思, 依照先進提供語法, 跑出來是全部計算出來筆數 10筆
//取出收銀員名字放到 name
$row 變數對應欄位名, 我試著使用$row['MU002']; 或是使用$row['收銀員'];
都是一樣結果.... 10筆, 而不是顯示出個別統計筆數 黃穗婷:3 王永靜:2 陳世珊:5
我這裡提供一下我的語法如下 : 是否那裡出現問題 ?? .... 不好意思, 再麻煩指點一下 謝謝~~
/* Show Field name */
while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC ) ) {
if (++$i == 1) { // 第一筆資料顯示欄位名稱
echo "<tr>";
foreach (array_keys($row) as $val) {
echo "<td>".$val."</td>";
}
echo "</tr>". "\n" ;
}
echo "<tr>";
foreach ($row as $val) {
echo "<td>".$val."</td>";
}
echo "</tr>". "\n" ;
$sumTC009 = $sumTC009 + $row['銷售付款金額'];
$sumTA029 = $sumTA029 + $row['總折價金額'];
$name=$row['收銀員'];
if(!isset($$name)){
$$name=0;
}
$$name++;
}
// echo "(銷售合計)=>" . "<font color=#ff0000>" .$sumTB033 ."元" ."</font>" ."</tr>". "\n";
echo "(銷售付款金額合計)=>" ."<font color=red>" .$sumTC009 . "元" ."</font>" ."</tr>". "\n";
echo "(總折價金額合計)=>" ."<font color=red>" .$sumTA029 . "元" ."</font>" ."</tr>". "\n";
echo "(黃穗婷)=>" . "<font color=red>" .$$name ."" ."</font>" ."</tr>". "\n";