Aide - Recherche - Membres - Calendrier
Version complète : Un birthday.php modifié ?
Forum osCommerce-fr > Adapter OsCommerce MS2 > Contributions
polo
Bonjour,


Voila j'ai réussi à réaliser à partir de la contrib "birthday.php" un tableau dont j'ai ajouté l'age du client, donc ce qui donne nom, prénom, sexe et age..

Par contre je voudrais ajouter une colonne "nombre de commande passé" voici le code que j'ai déjà fait:


le query:

Code
$geburtstags_query = tep_db_query("SELECT customers_email_address, customers_dob, customers_firstname, customers_id, customers_gender, customers_lastname FROM " . TABLE_CUSTOMERS . " WHERE MONTH(customers_dob) = MONTH(DATE_ADD(NOW(),INTERVAL 0 MONTH)) ORDER BY DAYOFMONTH(customers_dob)");

while ($geburtstag = tep_db_fetch_array($geburtstags_query)){
$gender = $geburtstag['customers_gender'];


if ($gender == 'm') {
$sex = 'Monsieur';
         } else {
$sex = 'Madame';
         }



ensuiite le tableau en lui même:

Code
  <tr align="left">
    
  <td width="100" valign="middle" bgcolor="#F0F1F1" class="main">&nbsp;<?php echo $geburtstag['customers_firstname']; ?></td>
  <td width="100" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo $geburtstag['customers_lastname']; ?></td>
  <td width="100" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo $sex; ?></td>
  <td width="100" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo substr(strftime(DATE_FORMAT_SHORT),6,4) - substr($geburtstag['customers_dob'],0,4); ?></td>
  
<td width="100" valign="middle" bgcolor="#F0F1F1" class="main"><?php echo $geburtstag['customers_email_address']; ?></td>
<td width="100" valign="middle" bgcolor="#F0F1F1" class="main"><?php echo $geburtstag['count(*)']; ?></td>
                </tr>
                <?php
      }
?>


Voila c'est justement ici:
Code
<?php echo $geburtstag['count(*)']; ?>


Comment ajouter l'instruction "count" dans mon query ?

Le query qui m'inspire est celui ci mais j'arrive pas à l'adapter :
Code
            $cusomers_order_count_query_raw = "select count(*) from orders where customers_id = " . $customers['customers_id'];
              $customers_order_query = tep_db_query($cusomers_order_count_query_raw);
              $order_count = tep_db_fetch_array($customers_order_query);


blush.gif
shoprun
Salut

Code
$cusomers_order_count_query_raw = "select count(*) from orders where customers_id = " . $customers['customers_id'];
Faudrait lui donner un nom je pense.

Comme ceci par exemple puis y mettre le nom du champ "orders_id" c'est pas plus mal nom plus, de même que typer (int) le $customers['customers_id'] :
Code
$cusomers_order_count_query_raw = "select count(orders_id) AS totCmd from orders where customers_id = '" . (int)$customers['customers_id']."' ";
Après, suffit d'exploiter cette donnée :
Code
$customers_order_query = tep_db_query($cusomers_order_count_query_raw);
$order_count = tep_db_fetch_array($customers_order_query);
echo 'Total commande : '.$order_count['totCmd'];
polo
Salut Shoprun,


Donc merci pour ton code, j'ai donc mis comme ceci:



Code
      
$geburtstags_query = tep_db_query("SELECT customers_email_address, customers_dob, customers_firstname, customers_id, customers_gender, customers_lastname FROM " . TABLE_CUSTOMERS . " WHERE MONTH(customers_dob) = MONTH(DATE_ADD(NOW(),INTERVAL 0 MONTH)) ORDER BY DAYOFMONTH(customers_dob)");

$cusomers_order_count_query_raw = "select count(*) AS totCmd from orders where customers_id = " . (int)$customers['customers_id'];
$customers_order_query = tep_db_query($cusomers_order_count_query_raw);
$order_count = tep_db_fetch_array($customers_order_query);
    
    
while ($geburtstag = tep_db_fetch_array($geburtstags_query)){
$gender = $geburtstag['customers_gender'];


if ($gender == 'm') {
$sex = 'Monsieur';
         } else {
$sex = 'Madame';
         }
         ////
?>
  <tr align="left">
    
  <td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="main">&nbsp;<?php echo $geburtstag['customers_firstname']; ?></td>
  <td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo $geburtstag['customers_lastname']; ?></td>
  <td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo $sex; ?></td>
  <td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo substr(strftime(DATE_FORMAT_SHORT),6,4) - substr($geburtstag['customers_dob'],0,4); ?></td>
  
<td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="main"><?php echo $geburtstag['customers_email_address']; ?></td>
<td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="main"><?php echo $order_count['totCmd']; ?></td>
                </tr>
                <?php
      }
?>


J'ai "0" dans le nombre des commande donc ç passe pas, par contr je ne doit pas utiliser $geburtstag ? comme :
Code
<?php echo $geburtstag['totCmd']; ?>
shoprun
A mon avis il faut que la requête se fasse dans la boucle du while ($geburtstag = tep_db_fetch_array($geburtstags_query)), car le $customers['customers_id'] est une variable inconnue.

Comme ceci je pense :
Code
while ($geburtstag = tep_db_fetch_array($geburtstags_query)) {
    // Recherche le nombre de commande
    $cusomers_order_count_query_raw = "select count(orders_id) AS totCmd from orders where customers_id = '" . (int)$geburtstag['customers_id']."' ";
    $customers_order_query = tep_db_query($cusomers_order_count_query_raw);
    $order_count = tep_db_fetch_array($customers_order_query);
    //

  $gender = $geburtstag['customers_gender'];
  ... code etc ...

}

Ceci dit, cette 2ème requête peut se fusionner dans la 1er pour en faire une seul. Pour cela faut faire les jointure + un GROUP BY sur le customers_id.
M'enfin, déjà vois si c'est bon en 2 requêtes wink.gif
polo
Oui c'est ce que j'ai essayer de faire aussi mais la j'ai un peu de mal pour la fusion,

Sinon j'ai fais ceci donc:
Code
$geburtstags_query = tep_db_query("SELECT customers_email_address, customers_dob, customers_firstname, customers_id, customers_gender, customers_lastname FROM " . TABLE_CUSTOMERS . " WHERE MONTH(customers_dob) = MONTH(DATE_ADD(NOW(),INTERVAL 0 MONTH)) ORDER BY DAYOFMONTH(customers_dob)");

    
while ($geburtstag = tep_db_fetch_array($geburtstags_query)){
$gender = $geburtstag['customers_gender'];

$cusomers_order_count_query_raw = "select count(*) AS totCmd from orders where customers_id = " . (int)$customers['customers_id'];
$customers_order_query = tep_db_query($cusomers_order_count_query_raw);
$order_count = tep_db_fetch_array($customers_order_query);

$nbrecmd = $order_count['totCmd'];


if ($gender == 'm') {
$sex = 'Monsieur';
         } else {
$sex = 'Madame';
         }
         ////
?>
  <tr align="left">
    
  <td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="main">&nbsp;<?php echo $geburtstag['customers_firstname']; ?></td>
  <td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo $geburtstag['customers_lastname']; ?></td>
  <td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo $sex; ?></td>
  <td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="smallText">&nbsp;<?php echo substr(strftime(DATE_FORMAT_SHORT),6,4) - substr($geburtstag['customers_dob'],0,4); ?></td>
  
<td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="main"><?php echo $nbrecmd; ?></td>
<td width="100" align="center" valign="middle" bgcolor="#F0F1F1" class="main"><?php  ?></td>
                </tr>
                <?php
      }
?>


Mais çà m'affiche toujours "0" pour les commandes.
shoprun
Tu n'as pas bien observé la requête wacko.gif

Remplace $customers['customers_id'] par $geburtstag['customers_id']
polo
Arf quel Nanare je fait, il fallait changer en $geburtstag['customers_id'] blush.gif


Encore merci Shoprun. smile.gif
Philblm
Salut.
Tout ça a l'air bien intéressent, mais, petite ceinture blanche à tout les niveaux, je ne sais pas comment on peut intégrer ce bout de code dans la page "birthday.php".
Si jamais vous avez le temps, je prend...
Merci d'avance.
Philblm
Salut!

Du coup, j'ai installé "Birthdays_v1.2" (ici), et elle fonctionne très bien!!! blush.gif

Bye!
polo
héhé temps mieux !! cool.gif
Ceci est une version "bas débit" de notre forum. Pour voir la version complète avec plus d'informations, la mise en page et les images, veuillez cliquer ici.
Invision Power Board © 2001-2013 Invision Power Services, Inc.