aide sql inner join peel 8.0.3

4 posts in this topic

Posted · Report post

bonjour

je souhaite exécuter ceci 

 

$sql = 'SELECT commande_id,produit_id,image1,nom_bill,prenom_bill,telephone_bill,email_bill,ville_bill,pays_bill,a_timestamp,nom_produit 
        FROM peel_commandes_articles AS a
        INNER JOIN peel_commandes AS c ON c.id=commande_id
        INNER JOIN peel_produits AS f ON produit_id=f.id
        WHERE a_timestamp >= \'2016-05-01 00:00:00.000000\' 
        ORDER BY commande_id ASC
        ';

mais limiter l'affichage du nombre de produits de chaque commande avec un LIMIT 5

pouvez vous m'aider car j'ai essayer plusieurs façon mais aucune ne fonctionne :

ex:

SELECT commande_id,produit_id,image1,nom_bill,prenom_bill,telephone_bill,email_bill,ville_bill,pays_bill,a_timestamp, nom_produit

FROM peel_commandes AS c 

INNER JOIN (select * from peel_commandes_articles LIMIT 5) peel_commandes_articles ON c.id=commande_id 

INNER JOIN peel_produits AS f ON produit_id=f.id 

WHERE c.a_timestamp >= '2016-07-01 00:00:00.000000'

cette solution ne me retourne du coup aucune ligne alors qu'il y en a !!!!

 

Share this post


: post
Share on other sites

Posted · Report post

Bonjour,

La clause LIMIT est à ajouter à la fin de la requête :

SELECT commande_id,produit_id,image1,nom_bill,prenom_bill,telephone_bill,email_bill,ville_bill,pays_bill,a_timestamp, nom_produit

FROM peel_commandes AS c 

INNER JOIN peel_commandes_articles ON c.id=commande_id 

INNER JOIN peel_produits AS f ON produit_id=f.id 

WHERE c.a_timestamp >= '2016-07-01 00:00:00.000000'
LIMIT 5

Share this post


: post
Share on other sites

Posted (edited) · Report post

merci pour cette réponse mais cette solution ne m'affiche que 5 résultats en tout alors que je souhaite afficher max 5 résultats PAR COMMANDE

 

 

<?php
include("configuration.inc.php");
$csv_filename = 'export_'.date("d-m-Y");



$sql = 'SELECT commande_id,produit_id,image1,nom_bill,prenom_bill,telephone_bill,email_bill,ville_bill,pays_bill,a_timestamp,
		nom_produit 
		
		FROM peel_commandes_articles AS a
		INNER JOIN peel_commandes AS c ON c.id=commande_id
		INNER JOIN peel_produits AS f ON produit_id=f.id
		WHERE a_timestamp >= \'2015-07-01 00:00:00.000000\' 
		ORDER BY commande_id ASC
		
		';


$result = query($sql);
$csv_export='id_order;email;lastname;firstname;date_order;id_product;nom;url_prod;url_image';
$csv_export .= "\n";
while ($row = fetch_assoc($result)) {
	$csv_export .= "".$row['commande_id'].";".$row['email_bill'].";".$row['nom_bill'].";".$row['prenom_bill'].";".$row['a_timestamp'].";".$row['produit_id'].";".$row['nom_produit'].";http://www.grossiste-en-accessoire.com/achat/produit_details.php?id=".$row['produit_id'].";http://www.grossiste-en-accessoire.com/upload/".$row['image1'].'"'; //Là aussi on remplace les ; par \t pour obtenir une tabulation
	$csv_export .= "\n";
}
 
// Export csv 
header("Content-type: text/x-csv; charset=utf-8");
header("Content-Disposition: attachment; filename=".$csv_filename.".csv");
print($csv_export);
?>
	

 

Edited by neomega

Share this post


: post
Share on other sites

Posted · Report post

Bonjour,

Dans ce cas vous devez ajouter une limitation en PHP dans la boucle while qui exploite les résultats. Pour limiter à 5 produits par commande, il faut dans un premier temps initialiser un compteur dans la boucle. Juste sous le while, vous pouvez ajouter :

if (empty($last_order_id) || (!empty($last_order_id) && $last_order_id != $row['commande_id'])) {
$i = 0;
}

en dessous, il faut placer l'exclusion des résultats si i$ == 5 :
if ($i >= 5) {
continue;
}

Ensuite tout en bas de la boucle, il faut ajouter l'incrémentation du compteur et la variable $last_order_id

$i++;
$last_order_id = $row['commande_id'];

 

Share this post


: post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

Twitter Advisto ecommerce

Facebook PEEL Shopping