Click to See Complete Forum and Search --> : help writing a query please


joshua4
03-11-2010, 10:11 AM
I need to grab all the articles and mediums joined to a particular section with say `section`.id = 4

I've tried this with no success but know it can be done. Thanks in advance for any guidance



CREATE TABLE IF NOT EXISTS `article` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`text` text NOT NULL,
`url` varchar(256) DEFAULT NULL,
`thumb_img` varchar(64) DEFAULT NULL,
`byline_id` int(11) DEFAULT '0',
`created_at` datetime DEFAULT '0000-00-00 00:00:00',
`updated_at` datetime DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `FK_article_user` (`created_by_id`),
KEY `FK_article_byline` (`byline_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=701 ;

CREATE TABLE IF NOT EXISTS `article_section` (
`article_id` int(11) NOT NULL,
`section_id` int(11) NOT NULL,
PRIMARY KEY (`article_id`,`section_id`),
KEY `FK_article_section_section` (`section_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


CREATE TABLE IF NOT EXISTS `medium` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(256) NOT NULL,
`description` varchar(256) NOT NULL,
`type` enum('audio','video','image') NOT NULL,
`url` varchar(256) NOT NULL,
`thumb_img` varchar(64) NOT NULL,
`full_img` varchar(64) NOT NULL,
`medium_channel_id` int(11) DEFAULT NULL,
`created_at` datetime DEFAULT '0000-00-00 00:00:00',
`updated_at` datetime DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `FK_media_user` (`created_by`),
KEY `FK_media_media_channel` (`medium_channel_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=701 ;

CREATE TABLE IF NOT EXISTS `medium_section` (
`medium_id` int(11) NOT NULL,
`section_id` int(11) NOT NULL,
PRIMARY KEY (`medium_id`,`section_id`),
KEY `FK_media_section_section` (`section_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `section` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) NOT NULL,
`path` varchar(30) NOT NULL,
`url` varchar(255) NOT NULL,
`title` varchar(50) NOT NULL,
`alt_title` varchar(50) DEFAULT NULL,
`browser_title` varchar(255) NOT NULL,
`description` varchar(255) DEFAULT NULL,
`text` tinytext NOT NULL,
`created_by_id` int(11) NOT NULL,
`created_at` datetime DEFAULT '0000-00-00 00:00:00',
`updated_at` datetime DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `url_unique` (`url`),
KEY `FK_page_user` (`created_by_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=497 ;

joshua4
03-12-2010, 10:40 PM
bump

Rexication
03-17-2010, 06:05 AM
From what Im reading I kinda understand what you want but what your showing isnt exactly going to grab them. Your just creating places to store information so to speak. If you want to grab articles from the Database then you will have to make the query too log into the Database and select the table etc. Also if you just want the Article title that's possible too.

Does this hit the spot close or even exactly on what you want?