lundi 3 juillet 2017

PHP: How to remove/disable a selection from a checkbox group if the value is already selected and stored in database previously

Right now I am coding in PHP & HTML


I need to make a selection from the checkbox group and It goes like this:

  1. The value in the dropdown menu is retrieved from the value stored in the database in table 'subject'. So the checkbox options will appears as (for example) Mathematics, Algebra, Calculus, English, Linguistic etc. -- I have no problem with displaying this one.

    **Table subject**
    
    subject_id       subject_name
    ==========       ============
         1            Mathematics
         2            Algebra
         3            Calculus
         4            English
         5            Linguistic
    
    
  2. So after that, a student can choose their subject and it will be stored in another table named student_subject where it stores the student_id and the subject_id (to store what subjects did a student chose) Example:

    **table student_subject**
    
    student_id       subject_id
    ==========       ===========
        1                 1
        1                 2                                           
        1                 3
        2                 1  
        2                 3   
    
    
  3. Now, the student comes again to add another subject in his profile. The same checkbox option will be displayed as mentioned earlier in (1) but I would love to disabled/remove/not display the already selected option from being selectable again to avoid redundancy.

I really have no idea on how to do this function. I know there are a lot of experienced programmer and developer here so I wish you could show me the right way. Your guidance is highly appreciated.




Aucun commentaire:

Enregistrer un commentaire