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

Bienvenue invité ( Connexion | Inscription )

 
Reply to this topicStart new topic
> Produits doublons dans specials.php, Erreur mysql en utilisant "select distinct"
Alix32
posté 6 Oct 2014, 14:00
Message #1


Ceinture jaune+ OSC
Icône de groupe

Groupe : Membres
Messages : 152
Inscrit : 31-January 07
Lieu : Bordeaux
Membre no 15025



Bonjour,

J'ai dupliqué quelques produits sur ma boutique car ils vivent aussi bien dans les accessoires pour hommes que dans les accessoires pour femmes. Je duplique mes produits en utilisant la fonction "copier vers" et en sélectionnant "Lien produit".

Certains de ces produits que j'ai dupliqué sont en promotion. J'ai une page "specials.php" qui affiche tous mes produits en promotion mais je trouve tous les produits dupliqués en doublon. Pour essayer de réparer ce probleme, j'ai rajouté "select distinct" dans mon code sql afin de rendre unique ma liste de produit.

Code
$specials_query_raw = "select distinct p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_SPECIALS . " s, " . TABLE_CATEGORIES . " c where p2c.categories_id = c.categories_id and p.products_status = '1' and p.products_quantity > 0 and p.products_id = p2c.products_id and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1'";


Mais j'ai cette erreur MySQL qui s'affiche:

Citation
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 '*) as total from products p, products_description pd, products_to_categories p2' at line 1

select count(distinct *) as total from products p, products_description pd, products_to_categories p2c, specials s, categories c where p2c.categories_id = c.categories_id and p.products_status = '1' and p.products_quantity > 0 and p.products_id = p2c.products_id and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '4' and s.status = '1'


Je ne suis pas un gourou de SQL - est-ce que quelqu'un pourrait m'aider a comprendre ce que je dois corriger svp?

Merci!

Ce message a été modifié par Alix32 - 6 Oct 2014, 14:02.


--------------------
En production:
Phoenix v1.0.7.6
Contributions: Categories Navbar Module - QTPro V7.2.0 - Store Pick Up V2.0 - Ultimate Seo Url V2.2d-21 - Discount Codes V5.3.2 - Header Tags SEO v3.3.11 - Header Status Handler - Kissit Image Thumbnailer Phoenix V3.5.0
Version de PHP et MySQL: PHP 7.2.31 / MySQL 5.5.30
Hébergement: OVH
Go to the top of the page
 
Bonbec
posté 7 Oct 2014, 07:23
Message #2


Ceinture marron OSC
Icône de groupe

Groupe : Modérateurs
Messages : 1543
Inscrit : 30-May 06
Lieu : Vichy (03)
Membre no 10583



Bonjour,

Je ne suis pas du tout à l'aise non plus avec MySql, mais je sais qu'on ne peut pas utiliser de joker (*) avec DISTINCT.
Il faut un nom de colonne.
Peut être que cela fonctionnera ? :
Code
select count(distinct products_name) as ...


--------------------
Config 1 en live : Osc 2.2 très fortement modifié ... UTF-8 et Php 5.4.
Contribs installées : down_for_maintenance_v 2.3 | Estimated Shipping v1.5 | imprint_1_3_5 | low_stock_report_v2.04 | visible_countries_1.2b | Products Tabs | shoppingCart_cleanup_v1.01.0 | + trop de bidouilles persos pas très OsCommerce (erreurs de jeunesse)
Config 2 en local avec UwAmp : Osc Phoenix
Go to the top of the page
 
Havock
posté 7 Oct 2014, 08:48
Message #3


Ceinture bleue OSC
Icône de groupe

Groupe : Membres
Messages : 912
Inscrit : 4-February 04
Membre no 1926



Bonjour Alix,

Bonbec a raison, tu dois specifier un champ pour ton distinct, sinon ça met le why smile.gif

Par contre j'ai un doute sur un point : la requête que tu nous cites et le message d'erreur ne semblent pas correspondre blink.gif Tu n'aurrais pas mis ton distinct * dans une autre requête ?


--------------------
L'indispensable est en cours de traitement,
L'urgent sera traité demain,
Le normal sera traité plus tard,
Le reste on vera ...
En conclusion : les journées sont trop courtes.
Utilisateur de MS2.2 Max 1.5 - OSC-Affiliate 1.09 - Admin With Access Levels 2.1 - Meta Tag Controller/ Generator - Credit/Gift Voucher/Coupons 5.05 - Download Controller v5.3 - X-Sell MS2 - WYSIWYG HTML Editor for Admin 1.7 - Dynamic Mo Pics - Loginbox Best - Order logging before payment processing - User Tracking - Faster Page Loads, Less DB queries - Plus plein de modifs perso :-)
Go to the top of the page
 
chti_poupon
posté 7 Oct 2014, 15:11
Message #4


Ceinture noire OSC
Icône de groupe

Groupe : TechDev
Messages : 2757
Inscrit : 9-September 08
Lieu : Douai
Membre no 22915



Bonjour
Pour faire simple, on recherche les produits en promotion (table specials) qui sont en stock et actifs (table products) et dont les id soient différents (table products). En effet, le produits dupliqués n'ont pas le même nom, mais le même id.
Rien à faire des catégories... !
Entre nous, dans admin - categories - promotions il y a pour chaque article - et ici très particulièrement ceux en double - un bouton "effacer" !!!
A moins de vouloir afficher les promotions par categories, ce qui n'est pas le problème posé.
Belle journée !
Chti poupon

Ce message a été modifié par chti_poupon - 8 Oct 2014, 09:03.
Raison de l'édition : méli mélo rectifié
Go to the top of the page
 
chti_poupon
posté 8 Oct 2014, 09:11
Message #5


Ceinture noire OSC
Icône de groupe

Groupe : TechDev
Messages : 2757
Inscrit : 9-September 08
Lieu : Douai
Membre no 22915



Ce qui nous donne:
Code
select distinct p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s " where p.products_status = '1' and p.products_quantity > 0 and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1'
Go to the top of the page
 
Alix32
posté 9 Oct 2014, 13:43
Message #6


Ceinture jaune+ OSC
Icône de groupe

Groupe : Membres
Messages : 152
Inscrit : 31-January 07
Lieu : Bordeaux
Membre no 15025



Merci Bonbec, Havock et chti_poupon d'avoir pris le temps de regarder mon probleme et de répondre.

@chti_poupon, du coup j'ai essayé de remplacer

Code
$specials_query_raw = "select distinct p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_SPECIALS . " s, " . TABLE_CATEGORIES . " c where p2c.categories_id = c.categories_id and p.products_status = '1' and p.products_quantity > 0 and p.products_id = p2c.products_id and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1'";


par le code que tu proposes

Code
$select distinct p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s " where p.products_status = '1' and p.products_quantity > 0 and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1'";


Mais ca me renvoie une erreur
Citation
Parse error: syntax error, unexpected T_STRING


J'ai l'impression que ca cloche vers
Code
" . TABLE_SPECIALS . " s " where p.products_status = '1'
.
J'ai essayé de bidouiller mais j'ai toujours cette erreur. Tu peux me mettre sur la bonne voie stp?

Merci encore pour vos retours!

Ce message a été modifié par Alix32 - 9 Oct 2014, 13:44.


--------------------
En production:
Phoenix v1.0.7.6
Contributions: Categories Navbar Module - QTPro V7.2.0 - Store Pick Up V2.0 - Ultimate Seo Url V2.2d-21 - Discount Codes V5.3.2 - Header Tags SEO v3.3.11 - Header Status Handler - Kissit Image Thumbnailer Phoenix V3.5.0
Version de PHP et MySQL: PHP 7.2.31 / MySQL 5.5.30
Hébergement: OVH
Go to the top of the page
 
chti_poupon
posté 9 Oct 2014, 15:10
Message #7


Ceinture noire OSC
Icône de groupe

Groupe : TechDev
Messages : 2757
Inscrit : 9-September 08
Lieu : Douai
Membre no 22915



Bonjour
J'avais donné la requête, pas la ligne entière ci-dessous:
Code
$specials_query_raw = "select distinct p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_quantity > 0 and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1'";

Il y avait bien un guillemet en trop juste avant where
Belle journée !
Chti poupon
Go to the top of the page
 
Alix32
posté 10 Oct 2014, 13:20
Message #8


Ceinture jaune+ OSC
Icône de groupe

Groupe : Membres
Messages : 152
Inscrit : 31-January 07
Lieu : Bordeaux
Membre no 15025



Aie, merci chti´poupon mais ca me renvoie ce meme type de message d'erreur:

Citation
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 '*) as total from products p, products_description pd, specials s where p.produc' at line 1

select count(distinct *) as total from products p, products_description pd, specials s where p.products_status = '1' and p.products_quantity > 0 and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '4' and s.status = '1'


Je ne comprends pas pourquoi j'ai ce "count" alors que la requete n'est pas construite pour compter mais bien pour extraire. Il transforme

Code
select distinct


en

Code
select count(distinct *) as total from products




--------------------
En production:
Phoenix v1.0.7.6
Contributions: Categories Navbar Module - QTPro V7.2.0 - Store Pick Up V2.0 - Ultimate Seo Url V2.2d-21 - Discount Codes V5.3.2 - Header Tags SEO v3.3.11 - Header Status Handler - Kissit Image Thumbnailer Phoenix V3.5.0
Version de PHP et MySQL: PHP 7.2.31 / MySQL 5.5.30
Hébergement: OVH
Go to the top of the page
 
Bonbec
posté 10 Oct 2014, 14:41
Message #9


Ceinture marron OSC
Icône de groupe

Groupe : Modérateurs
Messages : 1543
Inscrit : 30-May 06
Lieu : Vichy (03)
Membre no 10583



Re,
C'est pas possible que cela transforme biggrin.gif
Si tu regardes bien, les noms des champs ne sont pas les mêmes ... donc tu ne regardes pas la bonne requète dans ton code.


--------------------
Config 1 en live : Osc 2.2 très fortement modifié ... UTF-8 et Php 5.4.
Contribs installées : down_for_maintenance_v 2.3 | Estimated Shipping v1.5 | imprint_1_3_5 | low_stock_report_v2.04 | visible_countries_1.2b | Products Tabs | shoppingCart_cleanup_v1.01.0 | + trop de bidouilles persos pas très OsCommerce (erreurs de jeunesse)
Config 2 en local avec UwAmp : Osc Phoenix
Go to the top of the page
 
Alix32
posté 10 Oct 2014, 15:00
Message #10


Ceinture jaune+ OSC
Icône de groupe

Groupe : Membres
Messages : 152
Inscrit : 31-January 07
Lieu : Bordeaux
Membre no 15025



C'est fou ca.

Voila ma page entiere (oui des tables je sais... blush.gif).
Je sais que j'ai un compte de produits pour l'afficher sur ma grille. J'ai essayé d'enlever la ligne de code mais je'ai le meme message d'erreur.

Code
<?php

  require('includes/application_top.php');

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_SPECIALS);

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_SPECIALS));
$categories_id=0;
if(isset($HTTP_GET_VARS["categories_id"]) && ctype_digit(trim($HTTP_GET_VARS["categories_id"])))
  $categories_id=$HTTP_GET_VARS["categories_id"];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html <?php echo HTML_PARAMS; ?>>
<head>
<?php
/*** Begin Header Tags SEO ***/
if ( file_exists(DIR_WS_INCLUDES . 'header_tags.php') ) {
  require(DIR_WS_INCLUDES . 'header_tags.php');
} else {
?>
  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
  <title><?php echo TITLE; ?></title>
<?php
}
/*** End Header Tags SEO ***/
?>

<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" summary="" width="895" align="center" cellspacing="0" cellpadding="0">
                <tr>
                    <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
                </tr>
<!-- body_text //-->
      <tr>
        <td>
        <table border="0" summary="" width="100%" cellspacing="3" cellpadding="3">
          <tr>
          <?php /*** Begin Header Tags SEO ***/ ?>
            <td><h1>Promotions</h1></td>
          <?php /*** End Header Tags SEO ***/ ?>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '25'); ?></td>
      </tr>
<?php
  $specials_query_raw = "select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_SPECIALS . " s, " . TABLE_CATEGORIES . " c where p2c.categories_id = c.categories_id and p.products_status = '1' and p.products_quantity > 0 and p.products_id = p2c.products_id and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1'";
  
  if($categories_id > 0)
    $specials_query_raw .= " and p2c.categories_id in (".tep_get_categories_ids($categories_id).$categories_id.")";
    
  $specials_query_raw .= " order by p2c.categories_id, s.specials_date_added DESC";
  $specials_split = new splitPageResults($specials_query_raw, MAX_DISPLAY_SPECIAL_PRODUCTS);

  if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>
      <tr>
        <td>
<table border="0" summary="" width="895" cellspacing="0" cellpadding="2" align="center">
          <tr>
            <td class="listingBackground" style="border-top:solid;border-bottom:solid;border-width:1px;border-color:#D9D9D6;"><?php echo $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></td>
            <td class="listingBackground" style="border-top:solid;border-bottom:solid;border-width:1px;border-color:#D9D9D6;" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '30'); ?></td>
      </tr>
<?php
  }
?>
      <tr>
        <td><table border="0" summary="" width="100%" cellspacing="2" cellpadding="2">
          <tr>
<?php
    $row = 0;
    $specials_query = tep_db_query($specials_split->sql_query);
    while ($specials = tep_db_fetch_array($specials_query)) {
      $row++;

      echo '            <td align="left" width="2%" class="productListing" valign="top">
                            <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">
                            <span class="bottomBorder">' . tep_image(DIR_WS_IMAGES . $specials['products_image'], $specials['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</span></a>
                            <br><br>' . tep_get_manufacturers_image_listing($specials['products_id'], $manufacturer_name).'
                            <br><br><span class="allcaps">' . tep_get_manufacturers_name($specials['products_id']).'</span></br>
                            <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $specials['products_id']) . '">' . $specials['products_name'] . '</a>
                            <br><br><b><span class="productSpecialPriceCrossed">' .  $currencies->display_price($specials['products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</span>
                            &nbsp;|&nbsp;<b><span class="productSpecialPrice2">Promo: ' . $currencies->display_price($specials['specials_new_products_price'], tep_get_tax_rate($specials['products_tax_class_id'])) . '</span></b><br><br><br>' . "\n";
                        

      if ((($row / 4) == floor($row / 4))) {
?>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
          </tr>
          <tr>
<?php
      }
    }
?>
          </tr>
        </table></td>
      </tr>
<?php
  if (($specials_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>
      <tr>
        <td><br>
<table border="0" summary="" width="895" cellspacing="0" cellpadding="2" align="center">
          <tr>
            <td class="listingBackground" style="border-top:solid;border-bottom:solid;border-width:1px;border-color:#D9D9D6;"><?php echo $specials_split->display_count(TEXT_DISPLAY_NUMBER_OF_SPECIALS); ?></td>
            <td class="listingBackground" style="border-top:solid;border-bottom:solid;border-width:1px;border-color:#D9D9D6;" align="right"><?php echo TEXT_RESULT_PAGE . ' ' . $specials_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></td>
          </tr>
        </table></td>
      </tr>
<?php
  }
?>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>




--------------------
En production:
Phoenix v1.0.7.6
Contributions: Categories Navbar Module - QTPro V7.2.0 - Store Pick Up V2.0 - Ultimate Seo Url V2.2d-21 - Discount Codes V5.3.2 - Header Tags SEO v3.3.11 - Header Status Handler - Kissit Image Thumbnailer Phoenix V3.5.0
Version de PHP et MySQL: PHP 7.2.31 / MySQL 5.5.30
Hébergement: OVH
Go to the top of the page
 
chti_poupon
posté 10 Oct 2014, 15:11
Message #11


Ceinture noire OSC
Icône de groupe

Groupe : TechDev
Messages : 2757
Inscrit : 9-September 08
Lieu : Douai
Membre no 22915



Bonjour
+1@Bonbec
Je me souviens m'être battu avec select, *, count, distinct, () et toute la bande en implantant une contrib XXXX??.
Qu'as-tu récemment installé ?
La requête fautive peut aussi être dans l'un quelconque des nouveaux fichiers appelés (tout ce qu'il a après require, includes...) ou les fonctions modifiées (general, html_output...)
Cherches bien !
Belle journée !
Chti poupon
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 : 28th March 2024 - 18:11
Ce site est déclaré auprès de la commision Nationale
de l'Informatique et des Libertés (déclaration n°: 1043896)