[ cross selling ] Proposition d'articles

VaN
Mammouth du PHP | 1107 Messages

04 janv. 2010, 20:13

Bonjour,

J'ai une application, qui affiche une page détails d'un produit. Sur cette page, j'aimerai afficher une liste d'autres produits.
En gros, j'aimerai afficher les produits qui ont déjà été commandés avec cet article, sur les commandes précédentes.

Voici ma table commandes :
CREATE TABLE IF NOT EXISTS `achats` (
`achat_id` int(11) NOT NULL AUTO_INCREMENT,
`achat_commande_id` int(11) NOT NULL,
`achat_parent_id` int(11) NOT NULL,
`achat_item_id` int(11) NOT NULL,
`achat_item_type` tinyint(4) NOT NULL,
`achat_item_name` varchar(100) NOT NULL,
`achat_price` float NOT NULL,
`achat_quantity` tinyint(11) NOT NULL,
`achat_total` float NOT NULL,
`achat_statut` tinyint(4) NOT NULL,
PRIMARY KEY (`achat_id`),
KEY `achat_article_id` (`achat_item_id`),
KEY `achat_statut` (`achat_statut`),
KEY `achat_commande_id` (`achat_commande_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
Mais je n'arrive pas à formuler ma requête de manière à récupérer un tableau contenant les 4 premiers champs achat_item_id, classés par achat_quantity par ordre décroissant. J'ai l'impression que ce n'est pas possible en une seule requête en fait.

Une piste ?

EDIT : réponse trouvée, sur un autre forum : http://www.developpez.net/forums/d85841 ... ost4896785. Je rajoute le tag "cross selling" au titre du message, pour que ce thread soit facilement recensé par l'outil de recherche, ça pourrait aider des personnes qui cherchent à faire parei.

ViPHP
ViPHP | 5462 Messages

05 janv. 2010, 15:59

SELECT achat_item_id FROM achat ORDER BY achat_quantity DESC LIMIT 4
c'est quand meme pas ca que tu veux faire ?