Dynamic Form Field Showing Depends On Coloumn Value In Database

Hi i have table ‘student’ in database. I have columns to store student fess per semester. so i create column like this:

First_sem_total_fees,

First_sem_paid_fees,

First_sem_balance,

Second_sem_total_fees,

Second_sem_paid_fees,

Second_sem_balance.

I have created crud with gii tool. my form shows all the fields.

but i want if student has paid first semester total fees(balance is zero) then n only then form will show text fields for second sem fees.

Pls suggest some idea. Thank u

If you are using cactive form, you can do if-else in your code.

like




if($student->first_sem_paid_fees >0)

{

  // show the second term form fields

}



Reply, if this does not match your requirement.

Thank u for rplay

Actually i have 8 semester . so i have to do it in nested if statement. bcoz i want to checked whether previous sem fees has paid or not. But problem is that some courses have direct admission to third or fourth sem.

I think there is not shortcut for saving 8 if-else for this situation.

To check previous semester fees you can save previous semester column name in students table and check against this column name either in 8 if-else

OR

as follows,

Here $fee_col_name is one of the (First_sem_paid_fees,Second_sem_paid_fees,Third_sem_paid_fees,…).




$fee_col_name = $student->earlier_sem_colname;

if(empty($fee_col_name))

{

    // No earlier semester

   // This is first semester




}else

{

  // check earlier sem fees here

 if($student->$fee_col_name>0)

 {

    

 }

}



This is just a work around, I dont think it is ideal way, let see if others share their solution.