Results 1 to 2 of 2

Thread: Disjoint in PHP

  1. #1
    Join Date
    May 2009
    Posts
    62
    Thanks
    19
    Thanked 3 Times in 3 Posts

    Unhappy Disjoint in PHP

    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)...?

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    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:
    PHP Code:
    $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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •