[英]Pull 5 entries from DB, modify entries, put those 5 entries into an array so I can find the average
我正在從數據庫中提取5個條目,效果很好。 然后,我對每個條目進行一些數學運算以獲得不同的數字。 這5個數字將彼此相鄰顯示。 我需要將這5個條目放入一個數組,然后選擇這5個條目的平均值,所以我只有一個實數。
從mysql_fetch_array中,我提取了$ last_score,$ blue_rating和$ blue_slope作為最新的5個條目。 現在這是我的位置:
$query_p1 = "SELECT * FROM scorecards WHERE player_id='$player_id' LIMIT 5";
$result_p1 = mysql_query($query_p1);
while ($row_p1 = mysql_fetch_array($result_p1)) {
$blue_rating = $row_p1["blue_rating"];
$blue_slope = $row_p1["blue_slope"];
$last_score = $row_p1["total_score"];
$handicap = (((($last_score - $blue_rating) * 113) / $blue_slope) * .96);
echo "$handicap <br>";
}
這5個回聲是我在平均5個數組的單個陣列中所需的。非常感謝您的幫助。 謝謝。
代替
echo "$handicap <br>";
放
$handicaps[]= $handicap;
然后在循環之外您可以做
echo array_sum($handicaps)/5;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.