|
 |
|
อยากหาค่าเฉลี่ย ข้อมูล ที่ดึงออกมาโชว์คับ อยากหาค่าเฉลี่ย ข้อมูล ที่ดึงออกมาโชว์คับ คือ ดึงข้อมูล ออกมา แต่ละข้อมูล มี 3 ค่า |
|
 |
|
|
 |
 |
|
ก็แยก ออกมาแล้วเก็บใน array ให้หมด แล้วก็ วนลูป + กันทั้งหมด แล้ว / จำนวนทั้งหมด
ถ้าดึงจาก ฐานข้อมูล มันก็มี ฟังก์ชั่น หาค่าเฉลี่ยให้แล้วด้วย
รู้ช่วยได้อะเปล่า
|
 |
 |
 |
 |
Date :
2009-05-21 15:10:08 |
By :
ail2geal2 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
SQL:
AVG(your_field)
ถ้าไม่ใช้ แต่เป็อาเรย์
ตย.
Code (PHP)
<?php
$arr[] = array(1, 2, 3);
$arr[] = array(2, 3, 4);
$arr[] = array(3, 4, 5);
$to_divide = count($arr);
foreach($arr as $val){
$result[0] += $val[0];
$result[1] += $val[1];
$result[2] += $val[2];
}
echo 'average 1: '. $result[0]/$to_divide,
'average 2: '. $result[1]/$to_divide,
'average3: '. $result[2]/$to_divide;
?>
|
 |
 |
 |
 |
Date :
2009-05-21 15:22:44 |
By :
pjgunner |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
thank you ครับผม
|
 |
 |
 |
 |
Date :
2009-05-21 15:31:37 |
By :
mac1626 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมาก จะลองเอาไปทำดู
|
 |
 |
 |
 |
Date :
2009-06-17 00:49:24 |
By :
Thachina |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|