Log in

View Full Version : Disjoint in PHP



heavensgate15
03-01-2010, 03:10 PM
How would I know what table to access (insert) given the category from a super entity. Example, I have an entity examination (super entity) which have the attribute of exam_id (primary key), patient_id from the patient table, and the examtype which served as a category. If the examtype is health exam, I will insert on the healthexam table (sub entity). If the examtype is radiology, I will insert on the radiology table (sub entity). If the examtype is alcohol test, I will insert on the alcoholtest table (sub entity).

How to use the examtype from a super entity, to insert to a specific table (sub entity) where each examtype has a corresponding table (sub entity)...?

traq
03-02-2010, 12:19 AM
the simplest way would be to give each examtype the same name as the table it belongs in. Then you could just use that value in your query - but do a check to make sure it's a valid value first:


$examtype = // your "super entity" value (do you mean "superglobal", e.g., $_POST or $_GET?)
$OKexamtypes = array('healthexam', 'radiology', 'alcoholtest');

if(in_array($examtype, $OKexamtypes)){
$table = $examtype;
$SQL = "INSERT INTO `$table` ('column1_name', 'column2_name', 'etc') VALUES ('column1_value', 'column2_value', 'etc')";
// then perform your query
}