osCommerce France : Accueil Forum Portail osCommerce France Réponses aux questions Foire aux contributions

Bienvenue invité ( Connexion | Inscription )

 
Reply to this topicStart new topic
> Jointure de table, Pour etoffer un tableau de back office
kalago
posté 6 Oct 2007, 04:56
Message #1


Ceinture blanche OSC
Icône de groupe

Groupe : Membres
Messages : 19
Inscrit : 1-October 07
Membre no 19243



Bonjour,

Je voudrais completer un tableau de back office en rajoutant le num de transaction bancaire. J'ai une table cmcic_reference, qui comporte ces numeros.

Mon code est le suivant :

<?php

if (isset($HTTP_GET_VARS['cID'])) {

$cID = tep_db_prepare_input($HTTP_GET_VARS['cID']);

$orders_query_raw = "select o.orders_id, o.customers_name, o.customers_id, o.currency, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.customers_id = '" . (int)$cID . "' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by orders_id DESC";

} elseif (isset($HTTP_GET_VARS['status'])) {

$status = tep_db_prepare_input($HTTP_GET_VARS['status']);

$orders_query_raw = "select o.orders_id, o.customers_name, o.currency, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and s.orders_status_id = '" . (int)$status . "' and ot.class = 'ot_total' order by o.orders_id DESC";

} else {

$orders_query_raw = "select o.orders_id, o.customers_name, o.currency, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC";

}

Que faudrait-il ajouter pour adjoindre le champ "ref_id" de la table cmcic_reference ?
Go to the top of the page
 
fissiaux
posté 6 Oct 2007, 10:37
Message #2


5eme dan OSC
Icône de groupe

Groupe : Membres
Messages : 17048
Inscrit : 26-November 03
Lieu : Chez moi
Membre no 1669




Généralement, la question est dans le titre. Toi, c'est la réponse qui est dans le titre : "jointure de table" !!

Indique la structure de ta table cmcic_reference, et regarde quel est l'élément qui puisse permettre de faire cette jointure
Go to the top of the page
 
kalago
posté 6 Oct 2007, 13:20
Message #3


Ceinture blanche OSC
Icône de groupe

Groupe : Membres
Messages : 19
Inscrit : 1-October 07
Membre no 19243



CITATION(fissiaux @ 6 Oct 2007, 10:37) [snapback]253666[/snapback]
Généralement, la question est dans le titre. Toi, c'est la réponse qui est dans le titre : "jointure de table" !!

Indique la structure de ta table cmcic_reference, et regarde quel est l'élément qui puisse permettre de faire cette jointure


Merci de me répondre !

cmcic_reference comporte le champs orders_id, de quoi faire le lien si je comprends bien.

Par ailleurs, pour faire apparaitre le champ en question, voice ce que j'ai mis :

<td class="dataTableHeadingContent" align="center"><?php echo 'date achat'; ?></td>
<td class="dataTableHeadingContent" align="right"><?php echo 'Mode de paiement'; ?></td>
<td class="dataTableHeadingContent" align="right"><?php echo 'Num CIC'; ?></td> <-------------------------->
<td class="dataTableHeadingContent" align="right"><?php echo 'Statut'; ?></td>
<td class="dataTableHeadingContent" align="right"><?php echo 'N° de facture'; ?></td>

Go to the top of the page
 
fissiaux
posté 6 Oct 2007, 15:14
Message #4


5eme dan OSC
Icône de groupe

Groupe : Membres
Messages : 17048
Inscrit : 26-November 03
Lieu : Chez moi
Membre no 1669




Sur la premiere requete, ca pourrait donner un truc du genre

$orders_query_raw = "select cm.ref_id, o.orders_id, o.customers_name, o.customers_id, o.currency, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s, " . TABLE_CMCIC_REFERENCE . " cm where o.customers_id = '" . (int)$cID . "' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' and o.orders_id = cm.orders_id order by orders_id DESC";
Go to the top of the page
 
kalago
posté 6 Oct 2007, 15:37
Message #5


Ceinture blanche OSC
Icône de groupe

Groupe : Membres
Messages : 19
Inscrit : 1-October 07
Membre no 19243



Ca ne marche pas.

Alors j'ai plusieurs trucs :

- remplacé TABLE_CMCIC_REFERENCE . " cm where o.customers_id = '" .
par TABLE_CMCIC_REFERENCE . " cm where o.ref_id = '" .
Marche pas

- collé la chaine que vous proposez après } else {
Marche pas mais message 1146 - Table 'huilesetsens.TABLE_CMCIC_REFERENCE' doesn't exist
Et pourtant, quand je regarde mes tables dans phpadmin.online, j'ai cmcic_reference comme j'ai orders, orders_total, etc...

Une autre piste ?
Go to the top of the page
 
kalago
posté 6 Oct 2007, 16:49
Message #6


Ceinture blanche OSC
Icône de groupe

Groupe : Membres
Messages : 19
Inscrit : 1-October 07
Membre no 19243




La table n'était pas declarée. C'est chose faite. Mais pas d'amélioration...
Go to the top of the page
 
fissiaux
posté 6 Oct 2007, 18:49
Message #7


5eme dan OSC
Icône de groupe

Groupe : Membres
Messages : 17048
Inscrit : 26-November 03
Lieu : Chez moi
Membre no 1669




Les phrases comme "ca marche pas" ou "pas d'amélioration" me laissent ....

Comment veux tu que l'on t'aide si tu ne nous indiques pas ce que tu fais. Montre ton code modifié. Indique si message d'erreur. Si pas de mesage, mais que la valeur à lire n'est pas affichée, indique le code pour l'afficher....

Nous, on n'est pas derrière ton épaule, on voit pas ton écran, ....
Go to the top of the page
 
kalago
posté 6 Oct 2007, 19:17
Message #8


Ceinture blanche OSC
Icône de groupe

Groupe : Membres
Messages : 19
Inscrit : 1-October 07
Membre no 19243



CITATION(fissiaux @ 6 Oct 2007, 18:49) [snapback]253722[/snapback]
Les phrases comme "ca marche pas" ou "pas d'amélioration" me laissent ....

Comment veux tu que l'on t'aide si tu ne nous indiques pas ce que tu fais. Montre ton code modifié. Indique si message d'erreur. Si pas de mesage, mais que la valeur à lire n'est pas affichée, indique le code pour l'afficher....

Nous, on n'est pas derrière ton épaule, on voit pas ton écran, ....


OK OK, c'est vrai, pas très efficace ma manière de communiquer.

Reprenons : sur la premiere requete, rien ne se passe. Pas de message d'erreur. Mon tableau apparait mais la colonne "num CIC" reste vide.

Alors, j'ai utilisé votre code pour la troisième requete. Alors j'avais le message d'erreur rapporté plus haut. Depuis que j'ai modifié le fichier database_table.php avec :

define('TABLE_NEWSLETTERS', 'newsletters');
define('TABLE_ORDERS', 'orders');
define('TABLE_CMCIC_REFERENCE', 'cmcic_reference'); < ------------------ ajout -------------->
define('TABLE_ORDERS_PRODUCTS', 'orders_products');
define('TABLE_ORDERS_PRODUCTS_ATTRIBUTES', 'orders_products_attributes');

Je n'ai plus ce message d'erreur. Mais la colonne "num CIC" reste vide. Est-ce que la jonction se fait avec le bon champs ?

Mais peut etre le pble vient de ce code :

...
<td class="dataTableContent" align="right"><?php echo $cmcic_reference['ref_id']; ?></td> <------------- ici rajout------------>
<td class="dataTableContent" align="right"><?php echo $orders['orders_status_name']; ?></td>
<td class="dataTableContent" align="right"><?php echo $orders['orders_id']; ?></td>
...

Ma table cmcic est composée de 3 champs : ref_id, ref_number et orders_id (dans l'ordre) et c'est ref_id qui doit ressortir.

S'il faut autre chose, je reste devant l'ordi. Desolé encore.



Go to the top of the page
 
kalago
posté 6 Oct 2007, 19:28
Message #9


Ceinture blanche OSC
Icône de groupe

Groupe : Membres
Messages : 19
Inscrit : 1-October 07
Membre no 19243




Petit précision : si je colle le code préconisé à la place de la 3ème requete: j'ai le message suivant :
1054 - Unknown column 'cm.orders_id' in 'where clause'

select count(*) as total from orders o left join orders_total ot on (o.orders_id = ot.orders_id), orders_status s, cmcic_reference cm where o.customers_id = '0' and o.orders_status = s.orders_status_id and s.language_id = '4' and ot.class = 'ot_total' and o.orders_id = cm.orders_id
Go to the top of the page
 
kalago
posté 6 Oct 2007, 21:45
Message #10


Ceinture blanche OSC
Icône de groupe

Groupe : Membres
Messages : 19
Inscrit : 1-October 07
Membre no 19243



Bonjour,

Voilà la requete d'origine :

$orders_query_raw = "select o.orders_id, o.customers_name, o.customers_country, o.currency, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC";

Elle me permet de construire un tableau à partir de 3 tables :
TABLE_ORDERS qui comporte les champs orders_id, customers_name etc...
TABLE_ORDERS_TOTAL qui comporte les champs orders_total_id, text, etc...
TABLE_ORDERS_STATUS qui comporte les champs orders_status_id, languages_id, orders_status_name


Je souhaite introduire dans la requete une 4eme table :
TABLE_CMCIC_REFERENCE qui comporte les champs orders_id et ref_id, pour en extraire ref_id.

Je me suis lancé dans la rédaction d'une nouvelle requete, un peu à l'aveuglette :

$orders_query_raw = "select cm.ref_id, o.orders_id, o.customers_name, o.customers_country, o.currency, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_CMCIC_REFERENCE . " cm on (o.orders_id = cm.orders_id), " . TABLE_ORDERS_TOTAL . " ot on (cm.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC";

J'ai un message d'erreur :

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'on (cm.orders_id = ot.orders_id), orders_status s where o.orders

select count(*) as total from orders o left join cmcic_reference cm on (o.orders_id = cm.orders_id), orders_total ot on (cm.orders_id = ot.orders_id), orders_status s where o.orders_status = s.orders_status_id and s.language_id = '4' and ot.class = 'ot_total'

Voilà, j'espère que j'ai été moins brouillon que dans ma précédente tentative. En tout cas, j'ai besoin de ce tableau pour boucler ma compta (sinon, je doit pointer 1840 lignes à la main...).

Mille merci d'avance.
Go to the top of the page
 
fissiaux
posté 7 Oct 2007, 08:23
Message #11


5eme dan OSC
Icône de groupe

Groupe : Membres
Messages : 17048
Inscrit : 26-November 03
Lieu : Chez moi
Membre no 1669



remplace cm.orders_id par cm.order_id
Go to the top of the page
 
kalago
posté 7 Oct 2007, 14:31
Message #12


Ceinture blanche OSC
Icône de groupe

Groupe : Membres
Messages : 19
Inscrit : 1-October 07
Membre no 19243



Merci pour cette erreur. J'ai remplacé et j'obtiens un message d'erreur:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'on (cm.order_id = ot.orders_id), orders_status s where o.orders_

select count(*) as total from orders o left join cmcic_reference cm on (o.orders_id = cm.order_id), orders_total ot on (cm.order_id = ot.orders_id), orders_status s where o.orders_status = s.orders_status_id and s.language_id = '4' and ot.class = 'ot_total'

J'ai changé ma requete pour :

$orders_query_raw = "select cm.ref_id, o.orders_id, o.customers_name, o.customers_country, o.currency, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_CMCIC_REFERENCE . " cm on (o.orders_id = cm.order_id) left join " . TABLE_ORDERS_TOTAL . " ot on (cm.order_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' order by o.orders_id DESC";

J'obtiens des résultats (mon tableau apparait avec les num CIC), mais a un détail près : les commandes par chèque ou virements ne sont plus répertoriées. En fait, la serie order_id de cmcic_reference comporte des trous (1001, 1002, 1004...), ici 1003 est absent qui représente un paiement autre que par carte. Mais du coup, ces trous ne sont pas repris dans le tableau final, d'où une liste des achats qui est incomplète.

Je ne parviens pas à trouver l'astuce...
Go to the top of the page
 
Phocea
posté 8 Oct 2007, 12:43
Message #13


Ceinture marron OSC
Icône de groupe

Groupe : Membres
Messages : 1447
Inscrit : 12-March 05
Lieu : Chuiche
Membre no 5120



Essaye avec cette requete ou il te faudra remettre les noms des tables à la mode PHP, mais normalement ca marche

CODE
SELECT cm.ref_id, o.orders_id, o.customers_name, o.customers_country, o.currency, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, os.orders_status_name, ot.text as order_total
FROM orders o LEFT JOIN cmcic_reference cm ON (o.orders_id = cm.order_id),
orders_total ot,
orders_status os
WHERE o.orders_id = ot.orders_id
AND   ot.class = 'ot_total'
AND   o.orders_status = os.orders_status_id
AND   os.language_id = 1
ORDER BY o.orders_id DESC


Après tu peuxc nous poster ta contribution qui pourra eventuellement aider plein de gens qui ont le CIC smile.gif
Go to the top of the page
 

Reply to this topicStart new topic
1 utilisateur(s) sur ce sujet (1 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



RSS Version bas débit Nous sommes le : 25th May 2013 - 05:29
Ce site est déclaré auprès de la commision Nationale
de l'Informatique et des Libertés (déclaration n°: 1043896)