| Есть таблица товар и таблица с изображениями каждого товара
CREATE TABLE IF NOT EXISTS `cms_shop` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cid` int(11) DEFAULT '0',
`title` varchar(255) DEFAULT NULL,
`keywords` varchar(255) NOT NULL,
`time` datetime DEFAULT NULL,
`hometext` text,
`bodytext` text NOT NULL,
`field` text NOT NULL,
`comments` int(11) DEFAULT '0',
`counter` int(11) NOT NULL DEFAULT '0',
`ihome` int(1) NOT NULL DEFAULT '0',
`acomm` int(1) NOT NULL DEFAULT '0',
`votes` int(11) DEFAULT '0',
`totalvotes` int(11) DEFAULT '0',
`associated` text NOT NULL,
`code` varchar(15) DEFAULT NULL,
`picture` varchar(200) NOT NULL,
`preis` varchar(10) DEFAULT NULL,
`newpreis` varchar(100) NOT NULL,
`status` int(1) NOT NULL DEFAULT '0',
`weight` varchar(10) NOT NULL,
`action` int(1) NOT NULL,
`artikul` varchar(100) NOT NULL,
`msize` varchar(255) NOT NULL,
`wsize` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `catid` (`cid`),
KEY `counter` (`counter`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251;
|
CREATE TABLE IF NOT EXISTS `cms_images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cid` int(10) NOT NULL,
`catalog` varchar(150) DEFAULT '0',
`filename` varchar(300) NOT NULL,
PRIMARY KEY (`id`),
KEY `catid` (`catalog`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=49 ;
--
-- Дамп данных таблицы `cms_images`
--
INSERT INTO `cms_images` (`id`, `cid`, `catalog`, `filename`) VALUES
(48, 4, 'uploads/shop/4/', '1.jpg'),
(47, 4, 'uploads/shop/4/', '1.jpg'),
(46, 4, 'uploads/shop/4/', '1.jpg'),
(45, 2, 'uploads/shop/2/', '1.jpg'),
(44, 2, 'uploads/shop/2/', '1.jpg'),
(43, 2, 'uploads/shop/2/', '1.jpg'),
(42, 2, 'uploads/shop/2/', 'e6b1bcd3ac4f.jpg'),
(41, 2, 'uploads/shop/2/', '67e657cc8974.jpg'),
(40, 2, 'uploads/shop/2/', 'a5ccc9abd789.jpg'),
(39, 1, 'uploads/shop/1/', 'ba54969ae035.jpg'),
(38, 1, 'uploads/shop/1/', '0cfbeb78524a.jpg'),
(37, 1, 'uploads/shop/1/', '14639a31e99b.jpg'),
(36, 3, 'uploads/shop/3/', '5f64cbb58156.jpg'),
(35, 3, 'uploads/shop/3/', 'c3532a07aa63.jpg');
|
cid в cms_images это id товаров
Помогите грамотно правильно чтобы выводить одним запросом товар и все его фотографии или 2 фотографии | |