Ver Mensaje Individual
  #4 (permalink)  
Antiguo 10/08/2010, 11:54
Avatar de mortiprogramador
mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 8 meses
Puntos: 214
Respuesta: consulta rompecabezas

bueno, gracias por la gráfica, ahora bien, si entendi mejor el asunto,
pienso que la estructura de base de datos puede mejorarse (menos tablas por un lado, y por el otro las llaves serían numéricas)

pero pues tu problema actual es base de datos, porque?
bueno, no tenemos tu script de la creación y poblado de tablas, pero yo
en base a la imagen que pusiste, hice esto

Código MySQL:
Ver original
  1. nom varchar(20) not null, descripcio varchar(20) not null);
  2. type_input varchar(20) not null, variable varchar(20) not null);
  3. create table carregador (id int(2) not null, ordre int(2) not null,
  4. variable varchar(20) not null);
  5. variable varchar(20) not null, opt varchar(20) not null);
  6.  
  7. insert into titols (nom,descripcio) values
  8. ('llibres','llibres y revistes'),
  9. ('granformat','llibres y revistes'),
  10. ('targetes','llibres y revistes'),
  11. ('carteleria','llibres y revistes'),
  12. ('dispositivos_ele','llibres y revistes');
  13.  
  14. insert into cont_form (type_input,variable) values
  15. ('text','cantidad'),
  16. ('select','formato'),
  17. ('select','formato_digital'),
  18. ('select','incluye_portada');
  19.  
  20. insert into carregador (id,ordre,variable) values
  21. (4,1,'cantidad'),
  22. (4,2,'formato'),
  23. (4,3,'tipo_impresion'),
  24. (4,4,'plastificado'),
  25. (4,5,'tamaño_habierto'),
  26. (4,6,'hidden'),
  27. (4,7,'aceptar'),
  28. (5,1,'formato_digital'),
  29. (5,2,'cantidad'),
  30. (5,3,'hidden'),
  31. (5,4,'aceptar');
  32.  
  33. insert into form_select (variable,opt) values
  34. ('formato','normal'),
  35. ('formato','diptico'),
  36. ('formato','triptico'),
  37. ('formato_digital','cd'),
  38. ('formato_digital','dvd'),
  39. ('formato_digital','usb tarjeta');
  40.  
  41. y si uso la consulta más reciente publicada obtengo esto
  42.  
  43. +----+-----------------+----+
  44. | id | variable        | id |
  45. +----+-----------------+----+
  46. |  4 | formato         |  1 |
  47. |  4 | formato         |  2 |
  48. |  4 | formato         |  3 |
  49. |  5 | formato_digital |  4 |
  50. |  5 | formato_digital |  5 |
  51. |  5 | formato_digital |  6 |
  52. +----+-----------------+----+

ahora bien, analizemos por partes

tengo esto

Código MySQL:
Ver original
  1. select c.id, c.variable from cont_form f
  2. inner join carregador c on f.variable=c.variable
  3.  
  4. obteniendo
  5. +----+-----------------+
  6. | id | variable        |
  7. +----+-----------------+
  8. |  4 | cantidad        |
  9. |  4 | formato         |
  10. |  5 | formato_digital |
  11. |  5 | cantidad        |
  12. +----+-----------------+
  13.  
  14. y haciendo esto
  15.  
  16. select t.id, c.variable from carregador c
  17. inner join titols t on t.id=c.id
  18. inner join cont_form f on f.variable=c.variable
  19. order by t.id
  20.  
  21. se obtiene lo mismo,por ende es ausencia de datos lo que aquí ocurre,
  22. si hicieramos esto
  23.  
  24. insert into cont_form(type_input,variable) values
  25. ('select','cantidad'),
  26.  ('select','hidden');
  27.  
  28. y corremos cualquiera de las anteriores consultas,
  29. se obtiene esto:
  30.  
  31. +----+-----------------+
  32. | id | variable        |
  33. +----+-----------------+
  34. |  4 | cantidad        |
  35. |  4 | cantidad        |
  36. |  4 | formato         |
  37. |  4 | hidden          |
  38. |  5 | formato_digital |
  39. |  5 | cantidad        |
  40. |  5 | cantidad        |
  41. |  5 | hidden          |
  42. +----+-----------------+
  43.  
  44. y si quisieramos verlos sin repeticiones, bueno, con un group by bastaría
  45.  
  46. select c.id, c.variable from cont_form f
  47. inner join carregador c on f.variable=c.variable
  48. group by c.variable

sin embargo, si ejecutamos la consulta inicial (los inners) pues sigue sin
mostrarlos, así que seguramente algún join esta haciendo restricciones,
y de nuevo apunto al tema del mer de la bd, así que yo en tus zapatos
haría un buen análisis de la bd, y mejoraría su estructura

suerte y paciencia
saludos
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com