Welcome Guest, Not a member yet? Register   Sign In
Displaying Parent/Child lists
#1

[eluser]emuexplosion[/eluser]
My first post here, yay. =)

I've got a simple problem, but I can't seem to figure it out. I guess this deals more with logic than the coding side of things - but I am a designer, not a software engineer - but I'm hoping to bridge the gap a little with CI.

The complete outcome of this script needs to be a simple staff directory with an extension listing. My problem is when trying to sort each respective employee into their correct departments.

Code:
CREATE TABLE `departments` (
  `id` tinyint(4) NOT NULL auto_increment,
  `display` char(2) NOT NULL default '',
  `description` varchar(40) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

Code:
CREATE TABLE `staff` (
  `id` tinyint(4) NOT NULL auto_increment,
  `fname` varchar(20) NOT NULL default '',
  `lname` varchar(20) NOT NULL default '',
  `department` varchar(20) NOT NULL default '',
  `title` varchar(20) NOT NULL default '',
  `email` varchar(40) NOT NULL default '',
  `ext` varchar(6) NOT NULL default '',
  `cell` varchar(10) NOT NULL default '',
  `dayoff` char(2) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

Those are my two tables. One is departments which has an id, display (which is how I can control the order of the departments.. for example 'managers' will display before 'office staff') and then description. The other table has all the staff's info in it. The department field is where it keeps the ID of the department from the first table.

Right now, I've been able to get this output.

ie,

Bob - Accounting
Sue - Accounting
Billy - Service
John - Service
Tom - Service
Rena - Sales
Eric - Sales

-- But what I want to do is..

Accounting
Bob
Sue

Service
Billy
John
Tom

Sales
Rena
Eric

----

Make sense? Yeah it does, like I said it is a simple problem - but I'm not a coder, trying to learn. I thought I was doing pretty good figuring out the joins on the table, but getting it to display the way I want is proving to be harder than thought. Thanks!


Messages In This Thread
Displaying Parent/Child lists - by El Forum - 06-30-2007, 02:26 PM
Displaying Parent/Child lists - by El Forum - 06-30-2007, 04:23 PM
Displaying Parent/Child lists - by El Forum - 06-30-2007, 05:25 PM
Displaying Parent/Child lists - by El Forum - 07-01-2007, 03:46 AM
Displaying Parent/Child lists - by El Forum - 07-01-2007, 09:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB