problemas con consulta sobre 2 tablas la tabla producto i foto tienen una relacion de 1:1
la ruta de la fotos simpre me devuelve la primera /php/imagenes/grande/producto_grande.jpg /php/imagenes/pequena/producto_pequeno.jpg y no se porque
en el segundo tendria que salir /php/imagenes/grande/producto_grande1.jpg /php/imagenes/pequena/producto_pequeno1.jpg i siempre sale la misma fotografia
select nombre_producto,ruta_foto_grande,ruta_foto_pequena ,descripcion_producto from producto,foto where id_producto=producto_id_foto group by nombre_producte
nombre_producto ruta_foto_grande ruta_foto_pequena descripcion_producto
producto /php/imagenes/grande/producto_grande.jpg /php/imagenes/pequena/producto_pequeno.jpg descripcion producto
producto1 /php/imagenes/grande/producto_grande.jpg /php/imagenes/pequena/producto_pequeno.jpg descripcion producto1
CREATE TABLE IF NOT EXISTS producto (
id_producto SMALLINT (3) UNSIGNED ZEROFILL NOT NULL,
nombre_producto VARCHAR(25) UNIQUE NOT NULL,
descripcion_producto VARCHAR(550) NOT NULL,
producto_id_foto SMALLINT(4) UNSIGNED ZEROFILL NOT NULL,
producto_id_categoria SMALLINT (2) UNSIGNED ZEROFILL NOT NULL,
CONSTRAINT pk_id_producto PRIMARY KEY (id_producto),
CONSTRAINT fk_producto_id_foto FOREIGN KEY (producto_id_foto)
REFERENCES foto(id_foto),
CONSTRAINT fk_producto_id_categoria FOREIGN KEY (producto_id_categoria) REFERENCES categoria(id_categoria)
)ENGINE=InnoDB;
INSERT INTO producte (id_producte,nombre_producto,descripcion_producto, producto_id_foto,producto_id_categoria) VALUES (0,'producto','descripcion producto0',0000,0);
INSERT INTO producte (id_producte,nombre_producto,descripcion_producto, producto_id_foto,producto_id_categoria) VALUES (1,'producto1','descripcion producto1',0001,0);
CREATE TABLE IF NOT EXISTS foto (
id_foto SMALLINT(4) UNSIGNED ZEROFILL NOT NULL,
nombre_foto VARCHAR(50) UNIQUE NOT NULL,
ruta_foto_grande VARCHAR(50) NOT NULL,
ruta_foto_pequena VARCHAR(50) NOT NULL,
foto_id_categoria SMALLINT (2) UNSIGNED ZEROFILL NOT NULL,
CONSTRAINT pk_id_foto PRIMARY KEY (id_foto),
CONSTRAINT fk_foto_id_categoria FOREIGN KEY (foto_id_categoria) REFERENCES categoria(id_categoria)
)ENGINE=InnoDB;
INSERT INTO foto (id_foto,nombre_foto,ruta_foto_grande,ruta_foto_pe quena,foto_id_categoria) VALUES (0000,'producto','/php/imagenes/grande/producto_grande.jpg','/php/imagenes/pequena/producto_pequeno.jpg',00);
INSERT INTO foto (id_foto,nombre_foto,ruta_foto_grande,ruta_foto_pe quena,foto_id_categoria) VALUES (0001,'producto1','/php/imagenes/grande/producto1_grande.jpg','/php/imagenes/pequena/producto1_pequeno.jpg',00); |