Jump to content

Linking tables


jobs1109

Recommended Posts

Hi I got three tables (employers , company ,  and  Jobs) Employer table holds info about employer. Company hold info about the company and jobs table holds info about jobs. I was just wandering what would be a good way to link these tables in the database ?  Here is the coding for each table.

 

 

Employer Table

 


CREATE TABLE IF NOT EXISTS `employers` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

 

Jobs Table

 

CREATE TABLE IF NOT EXISTS `Jobs` (
  `id` int(11) NOT NULL,
  `JobTitle` varchar(200) default NULL,
  `Company` varchar(200) default NULL,
  `Salary` varchar(30) default NULL,
  `Description` varchar(2000) default NULL,
  `CompanyURL` varchar(200) default NULL,
  `PhoneNumber` varchar(30) default NULL,
  `Requirements` varchar(2000) default NULL,
  `JobCategory` varchar(100) default NULL,
  `JobType` varchar(100) default NULL,
  `Apply_To` varchar(1000) NOT NULL,
  `Email` varchar(200) NOT NULL,
  `modified_at` datetime NOT NULL,
  `PostedOnDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `Address` varchar(250) NOT NULL,
  `State` varchar(200) NOT NULL,
  `City` varchar(200) NOT NULL,
  `Country` varchar(100) NOT NULL,
  `Zipcode` varchar(100) NOT NULL,
  `JobID` varchar(100) NOT NULL,
  `WorkExperience` varchar(2000) NOT NULL,
  `EducationRequirement` varchar(2000) NOT NULL,
  `WebsitePostedFrom` varchar(200) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

 

Company Table

 


CREATE TABLE IF NOT EXISTS `Company` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `CompanyName` varchar(100) NOT NULL,
  `Address` varchar(100) NOT NULL,
  `Logo` varchar(100) NOT NULL,
  `PhoneNumber` varchar(25) NOT NULL,
  `ContactPerson` varchar(25) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;

Link to comment
https://forums.phpfreaks.com/topic/248184-linking-tables/
Share on other sites

In your jobs and employer tables you need to create a column called something like, company_id.

Then whenever a job or employer is created you can put the company table's unique ID into the respective table..

Example.

A new job is created for "Bobs Shop" company, Bobs Shop has an ID of 53. When you create the job you enter in all the information and put 53 into the company_id field. Thus completing the relationship between the 2 tables :)

 

I also noticed that your job and employer tables do not have an auto incrementing id field, might be a good idea to add that.

Link to comment
https://forums.phpfreaks.com/topic/248184-linking-tables/#findComment-1274499
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.