01.
<?php
02.
03.
$host
=
"localhost"
;
04.
$username
=
"root"
;
05.
$pass_word
=
"1234"
;
06.
$db
=
"ebandit"
;
07.
$Conn
= mysql_connect(
$host
,
$username
,
$pass_word
)
or
die
(
"ติดต่อฐานข้อมูลไม่ได้"
);
08.
mysql_query(
"SET NAMES utf8"
,
$Conn
);
09.
mysql_select_db(
$db
)
or
die
(
"เลือกฐานข้อมูลไม่ได้"
);
10.
$sql
=
"SELECT * FROM evaluation WHERE bandit_id='$bandit_id' "
;
11.
echo
$sql
;
12.
$query
=
$mysql_query
(
$sql
);
13.
while
(
$result
= mysql_fetch_array(
$query
))
14.
{
15.
$arr
[] =
$result
[
'ch1, ch2,ch3'
];
16.
}
17.
echo
Average(
$arr
);
18.
19.
function
Average(
$arr
) {
20.
$array_size
=
count
(
$arr
);
21.
22.
$total
= 0;
23.
for
(
$i
= 0;
$i
<
$array_size
;
$i
++) {
24.
$total
+=
$arr
[
$i
];
25.
}
26.
27.
$average
= (float)(
$total
/
$array_size
);
28.
return
$average
;
29.
}
30.
?>