For a website I am working on I have different widgets. For this section I use three tables:
- widgets
- widget_content
- widget_photos
In most cases things are quite straightforward like this:
- tbl widgets: widget_name
- tbl widget_content: heading & content
- tbl widget_photos: photo
But in some cases the situation is slightly different. One widget, for example, has three rows in the widget_content tbl and three in the widget_photos tbl where each photo is related to a certain row in the widget_content tbl. Here is the table structure to illustrate what i mean
CREATE TABLE IF NOT EXISTS `site_widgets` (
`widget_id` smallint(6) NOT NULL AUTO_INCREMENT,
`widget_name` varchar(64) NOT NULL,
`isActive` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`widget_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `site_widgets` (`widget_id`, `widget_name`, `isActive`) VALUES
(1, 'Season dates', 1);
CREATE TABLE IF NOT EXISTS `widget_content` (
`content_id` smallint(6) NOT NULL AUTO_INCREMENT,
`widget_id` smallint(6) NOT NULL,
`heading` varchar(128) DEFAULT NULL,
`sub_heading` varchar(255) DEFAULT NULL,
`content` text,
PRIMARY KEY (`content_id`),
KEY `widgetId` (`widget_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `widget_content` (`content_id`, `widget_id`, `heading`, `content`) VALUES
(1, 1, 'Spring season', 'This spring we will be open from March 15 till June 15'),
(2, 1, 'Summer season', 'The summer season we are open for tandem flights & visiting pilots after prior communication.'),
(3, 1, 'Autumn season', 'In fall we will be open from the 1st of September till the 17th November.');
CREATE TABLE IF NOT EXISTS `widget_photos` (
`id` smallint(6) NOT NULL AUTO_INCREMENT,
`rel_id` tinyint(4) DEFAULT NULL,
`photo` varchar(128) NOT NULL,
PRIMARY KEY (`id`),
KEY `relId` (`rel_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `widget_photos` (`id`, `rel_id`, `photo`) VALUES
(1, 1, 'flying_paradise_spring.jpg'),
(2, 2, 'flying_paradise_summer.jpg'),
(3, 3, 'flying_paradise_fall.jpg');
So widget Season dates has 3 related rows in the table widget_content related by widget_id => widget_id and each row in widget_content has a related photo in the widget_photos tbl related by content_id => rel_id
My question i how the query hould look like so I can loop over them in the View in PHP so that the related content and photos are displayed in panels like this:
Thank you in advance