Welcome Guest, Not a member yet? Register   Sign In
unable to display values from array in a view
#8

(This post was last modified: 11-25-2017, 01:49 PM by PaulD. Edit Reason: minor typos )

Try something like this:
PHP Code:
public function get_fee_invoice_4class($data)
{
    
// set return variable
    
$result = array();
    
    
// get students
    $students = $this->anotherDb->from('users')
        ->where('class_id'$data['id'])
        ->where('activated'1)
        ->where('role''Student')
        ->get()
        ->result_array();

    
// get payment details
    if ( ! empty($students) )
    {
        foreach (
$students as $student)
        {
            $result[] = $this->anotherDb->from('payments')
                ->select('payment_amount','payment_description','payment_student')
                ->where('payment_student', $student['id'])
                ->where('date_format(fee_month,"%d-%m%Y") >=date_format(curdate(),"00-%m-%Y")')
                ->where('payment_status'0)
                ->get()
                ->result_array();
        }
    }

    return $result;      
}  

Should work, however this is BAD, because imagine you have 1000 students, then you will have 1000 database calls because of running a query in a loop. I think what you really need is a more complex query with a join from students to students payments to get all the data in one query.
Reply


Messages In This Thread
RE: unable to display values from array in a view - by PaulD - 11-25-2017, 01:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB