PHP - 3065 - Expression #1 of ORDER BY clause is not in SELECT list,

 
Vista:
sin imagen de perfil
Val: 8
Ha aumentado su posición en 19 puestos en PHP (en relación al último mes)
Gráfica de PHP

3065 - Expression #1 of ORDER BY clause is not in SELECT list,

Publicado por Jame (2 intervenciones) el 01/05/2020 20:47:59
Hola,

Como consecuencia de una subida de version de PHP y MYSQL en el servidor donde tengo alojado mi pagina web, esta ha dejado de funcionar y se visualiza el siguiente mensaje de error:

3065 - Expression #1 of ORDER BY clause is not in SELECT list, references column 'bienesta_new.p.products_ordered' which is not in SELECT list; this is incompatible with DISTINCT

select distinct p.products_id, pd.products_name from products p, products_description pd where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '2' order by p.products_ordered desc, pd.products_name limit 10



Esto ocurre con las dos siguientes instrucciones del codigo PHP:

1
2
3
4
5
6
7
8
9
10
<?php
// optional Product List Filter
    if (PRODUCT_LIST_FILTER > 0) {
      if (isset($HTTP_GET_VARS['manufacturers_id']) && !empty($HTTP_GET_VARS['manufacturers_id'])) {
        $filterlist_sql = "select distinct c.categories_id as id, cd.categories_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p.products_status = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' order by cd.categories_name";
      } else {
        $filterlist_sql= "select distinct m.manufacturers_id as id, m.manufacturers_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by m.manufacturers_name";
      }
      $filterlist_query = tep_db_query($filterlist_sql);
      if (tep_db_num_rows($filterlist_query) > 1)



Versiones en el servidor:

MySQL: 5.7
PHP: Superior a 7.0


No tengo mucho conocimiento de PHP, alguien me podría ayudar para solventar este problema?

Gracias de antemano.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Julio
Val: 2.007
Plata
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

3065 - Expression #1 of ORDER BY clause is not in SELECT list,

Publicado por Julio (830 intervenciones) el 01/05/2020 20:53:01
Hola.

El problema no está en PHP, sino en la sentencia SQL. Fíjate, te dice que la expresión que utilizas como ORDER BY (p.products_ordered) NO está dentro de las opciones devueltas en el SELECT y que eso es incompatible con la instrucción DISTINCT.

Por tanto, imagino que si añades el p.products_ordered en el SELECT, se te arreglará el problema.

-----------------------------
Aprende la programación desde una perspectiva básica y simplista en Programación Básica
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 8
Ha aumentado su posición en 19 puestos en PHP (en relación al último mes)
Gráfica de PHP

3065 - Expression #1 of ORDER BY clause is not in SELECT list,

Publicado por jame (2 intervenciones) el 02/05/2020 12:40:07
Gracias por tu respuesta.

He intentado aplicar las consignas pero sigo con el mismo error:

3065 - Expression #1 of ORDER BY clause is not in SELECT list, references column 'bienesta_new.p.products_ordered' which is not in SELECT list; this is incompatible with DISTINCT

1
select distinct p.products_id, pd.products_name from products p, products_description pd, products_to_categories p2c, categories c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '2' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '30' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit 10


Puse

1
2
3
4
$filterlist_sql = "select distinct c.categories_id as id, cd.categories_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p.products_status = '1' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p2c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = '" . (int)$HTTP_GET_VARS['manufacturers_id'] . "' order by c.categories_id desc, cd.categories_name limit 10 ";
} else {
 
    $filterlist_sql= "select distinct  m.manufacturers_id as id, m.manufacturers_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by  m.manufacturers_id desc, m.manufacturers_name limit 10 ";


Teniendo en cuenta que el primer criterio utilizado a continuación del Order By es: c.categories_ para la primera Select y m.manufacturers para la segunda Select, estos criterios de ordenación están bien en la clausula SELECT...... Si he entendido bien el nombre p.products_id es un ejemplo que hay que seguir, pero debo usar las variables que están en la clausula original?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de javier
Val: 1.542
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

3065 - Expression #1 of ORDER BY clause is not in SELECT list,

Publicado por javier (547 intervenciones) el 02/05/2020 13:21:47
prueba asi:

1
$filterlist_sql= "select distinct m.manufacturers_id as id, m.manufacturers_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by id desc, name limit 10 ";
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Julio
Val: 2.007
Plata
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

3065 - Expression #1 of ORDER BY clause is not in SELECT list,

Publicado por Julio (830 intervenciones) el 02/05/2020 14:10:01
Creo que no me has entendido.

3065 - Expression #1 of ORDER BY clause is not in SELECT list, references column 'bienesta_new.p.products_ordered' which is not in SELECT list; this is incompatible with DISTINCT

Te dice que p.products_ordered no puede colocarse en el ORDER BY porque no está en los valores que devuelve el SELECT.

Luego pone:

1
select distinct p.products_id, pd.products_name from products p, products_description pd, products_to_categories p2c, categories c where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '2' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '30' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit 10

Fíjate lo que te he marcado en negrita. En el SELECT sólo pones p.products_id y pd.products pero no está p.products_ordered. El error te dice que p.products_ordered debe estar entre los elementos que devuelve el SELECT, así que tienes que ponerlo y hacer SELECT DISTINCT p.products_id, pd.products, p.products_ordered FROM ...

-----------------------------
Aprende la programación desde una perspectiva básica y simplista en Programación Básica
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar