MySQL Forums
Forum List  »  Newbie

Re: option value referencing
Posted by: Barry Galbraith
Date: March 15, 2015 03:07PM

Where did you get the value of 21 for Engineer? Intead of hardcoding it in your php, retrieve it from a table (job) in your database, where you might have something like this.

DROP TABLE IF EXISTS job;

CREATE TABLE job (
  id int(10) unsigned NOT NULL AUTO_INCREMENT,
  job varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;

/*Data for the table `job` */

insert  into job(id,job)
 values (1,'Manager')
 ,(2,'Owner')
 ,(3,'Director')
 ,(4,'Clerk')
 ,(5,'Engineer')
 ,(6,'Janitor')
 ,(7,'Worker')
 ,(8,'Jack of all trades')
 ;

Then you can add more job titles without changing your code. Just fill your option list for display with the result of a query on the job table. Save the value of the option in the "person" table, and join will tell you what job a person does.

Good luck,
Barry.

Options: ReplyQuote


Subject
Written By
Posted
March 15, 2015 11:20AM
Re: option value referencing
March 15, 2015 03:07PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.