In mysql database I have 5 tables stored. I am using php for storing and retrieving data. I would like to retrieve/echo/display information of those 5 tables but in a linked manner. I have academy_id
as the foreign key on each table. Each academy has a contact person. Some academies may share the same contact person. But not sure how I can display each academy with its unique information. How can I can display these values through php/mysql select query?
Academy Name | MOU_ID | Academy_ID | STATUS | Academy Created | Course Name | Course Start Date | Instructor First Name | Contact First Name
Tables
CREATE TABLE IF NOT EXISTS `academies` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(25) NOT NULL,
`mou_id` int(11) default NULL,
`academy_id` int(11) NOT NULL,
`status` enum('INACTIVE','ACTIVE') NOT NULL default 'ACTIVE',
`created_date` date NOT NULL
PRIMARY KEY (`id`)
);
INSERT INTO `courses` (`course_id`, `course_name`) VALUES
(1, 'MATH'),
(2, 'ENGLISH'),
(3, 'BIOLOGY'),
CREATE TABLE IF NOT EXISTS `academy_courses` (
`unique_id` int(11) NOT NULL auto_increment,
`academy_id` int(11) NOT NULL,
`course_id` int(11) NOT NULL,
`start_date` date default NULL,
PRIMARY KEY (`unique_id`),
KEY `course_id` (`academy_id`,`course_id`)
);
CREATE TABLE IF NOT EXISTS `instructors` (
`instructor_id` int(11) NOT NULL auto_increment,
`academy_id` int(11) NOT NULL,
`instructor_fname` varchar(50) NOT NULL
PRIMARY KEY (`instructor_id`),
KEY `academy_id` (`academy_id`)
);
CREATE TABLE IF NOT EXISTS `main_contact` (
`contact_id` int(11) NOT NULL auto_increment,
`academy_id` int(11) NOT NULL,
`contact_fname` varchar(50) NOT NULL,
PRIMARY KEY (`contact_id`),
KEY `academy_id` (`academy_id`)
);
CREATE TABLE IF NOT EXISTS `main_contact_bridge` (
`academy_id` int(11) NOT NULL,
`contact_id` int(11) NOT NULL,
PRIMARY KEY (`contact_id`,`academy_id`),
KEY `academy_id` (`academy_id`)
);