Grouping Results - Need Help!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
cdrees
Forum Newbie
Posts: 7
Joined: Wed Dec 21, 2005 9:26 am

Grouping Results - Need Help!!

Post by cdrees »

Hello Everyone,


I have a DB that I'm developing, that I've currently got functional, but I want to clean up the output.

Currently, I have a site that displays currently available courses, listed by date. It shows the following:

Course Date Course Title Notes
======================================================
2005-12-20 Course1 9am-5pm
2005-12-23 Course2 6pm-10pm
2005-12-26 Course1 9am-5pm
2005-12-30 Course1 9am-5pm


I'd like it to group by Course (if one is schedule), list the actual course title only once in my output, and then under each Course Title Heading list the dates and notes, like so:

Course One
===============================================
2005-12-20 9am-5pm
2005-12-26 9am-5pm
2005-12-30 9am-5pm

Course Two
===============================================
2005-12-23 6pm-10pm



I have three tables currently, one to hold the courses, one to hold locations, and one to hold scheduled dates:

PHP Code:
CREATE TABLE `academy_loc` (
`loc_id` int(5) NOT NULL auto_increment,
`location_st` varchar(5) collate latin1_general_ci NOT NULL,
`location_co` varchar(25) collate latin1_general_ci default NULL,
PRIMARY KEY (`loc_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=3 ;



CREATE TABLE `academy_main` (
`main_id` int(5) NOT NULL auto_increment,
`loc_id` int(5) NOT NULL,
`course_title` varchar(150) collate latin1_general_ci default NULL,
`course_desc` text collate latin1_general_ci,
`class_type` varchar(15) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`main_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=40 ;



CREATE TABLE `academy_sched` (
`sched_id` int(11) NOT NULL auto_increment,
`main_id` int(11) NOT NULL,
`course_date` date default NULL,
`sched_notes` text collate latin1_general_ci,
PRIMARY KEY (`sched_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=75 ;



I am thinking this is relatively simple to do, I've seen it done many times before, but I can't seem to get my head around it. Thanks so much!!

:wink:
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

DO NOT DOUBLE POST!

viewtopic.php?t=42119&highlight=

LOCKED.
Locked