$result = $MySQL->query('SELECT id, artist, title, ext, views, comments, favourites FROM `table` ORDER BY id DESC'); while ( $result_array = $MySQL->fetch_array($result) ) { $count[$result_array["id"]] = $result_array["views"] + ($result_array["comments"]*2) + ($result_array["favourites"]*5); // Also take in note the timeline $count[$result_array["id"]] = $count[$result_array["id"]]; // Now add some other information to the array $count[$result_array['id']]["id"] = $result_array["id"]; $count[$result_array['id']]["title"] = $result_array["title"]; $count[$result_array['id']]["artist"] = $result_array["artist"]; }