13-10-2008, 12:20 AM
La première idée qui me vient est de simplement intégrer les calculs comme des sous-requêtes. Comme cela :
Code PHP :
<?php
SELECT warehouses.id AS warehouse_id,
warehouses.capacityMech,
warehouses.capacityWeight,
warehouses.countries_id,
player_has_warehouse.name AS warehouse_name,
(
(
SELECT SUM(armors.weight)
FROM armors, players_has_armor
WHERE player_has_armor.players_id = $this->playerSess['id']
AND player_has_armor.armors_id = armors.id
)
+
(
SELECT SUM(weapons.weight)
FROM weapons, player_has_weapon
WHERE player_has_weapon = $this->playerSess['id']
AND player_has_weapon.weapons_id = weapons.id
)
) AS weight,
(
SELECT COUNT(player_has_exomech.id)
FROM player_has_exomech
WHERE player_has_exomech.players_id = $this->playerSess['id']
) AS nb_mechs,
countries.name AS country_name
FROM player_has_warehouse,
warehouses
JOIN countries
ON warehouses.countries_id = countries.id
WHERE player_has_warehouse.players_id = $this->playerSess['id']
AND player_has_warehouse.warehouses_id = warehouses.id;
N'est-il pas plus propre (bien qu'un peu plus verbeux) d'effectuer les jointures explicitement (avec JOIN ON) plutôt que de les faire dans la clause WHERE ?
Par contre, ces informations ont tout intérêt à être mises en cache. :O
Sephi-Chan, qui va se coucher, lui aussi…