Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Wie werden die sekundären Datensätze in der untergeordneten Zeile der Datentabelle mit der entsprechenden ID angezeigt?

Nach der ersten Idee würde der Controller mit einem Detail-Popup wie folgt aussehen:

public function Listdetails_ajax(){  
   $draw = intval($this->input->get("draw"));
    $start = intval($this->input->get("start"));
    $length = intval($this->input->get("length"));
    $books = $this->Search_model->getTotalList_of_primary();

    $data['draw'] = 1;
    $data['recordsTotal'] = count($books);
    $data['recordsFiltered'] = count($books);
    foreach ($books as $key => $row) 
    {
        //print_r($row->customer_id);
        $arr_result = array(
                    "member_id" => base64_encode($this->encryption->encrypt($row->member_id)),
                    "profile_pic" => $row->profile_pic,
                    "name" => $row->first_name.' ' .$row->last_name,
                    "phone" => $row->phone,
                    "chss_no" => $row->chss_no,
                    "emp_id" => $row->emp_id,
                    "address" => $row->address
                    // "member_type" => $row->member_type
        );

         $array_secondary = array();
         $books_of_secondary = $this->Search_model->getTotalList_of_secondary($row->customer_id);
         foreach ($books_of_secondary as $key => $row) 
            {
                //print_r($row->customer_id);
                $arr_result2 = array(
                            "s_member_id" => base64_encode($this->encryption->encrypt($row->member_id)),
                            "s_profile_pic" => $row->profile_pic,
                            "s_name" => $row->first_name.' ' .$row->last_name,
                            "s_phone" => $row->phone,
                            "s_chss_no" => $row->chss_no,
                            "s_emp_id" => $row->emp_id,
                            "s_address" => $row->address
                );


                $array_secondary[] = $arr_result2;
            }
         $arr_result['secondary'] =  $array_secondary;  
         $data['data'][] = $arr_result;
      }
    echo json_encode($data);
    exit;
}

Und dann würden Sie in der Formatfunktion auf den secondary zugreifen Feld, um ein Array von Secondaries zu erhalten. Vielleicht so:

function format(d) {
    // d is the original data object for the row var val;
    if(d.secondary.length == 0) {
        return "There are no secondary members";
    }

    var display = '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'; 
    for (val of d.secondary) { 
        display += '<tr>' + '<td>Full name:</td>' + '<td>' + val.s_name + '</td>' + '</tr>' + '<tr>' + '<td>Mobile number:</td>' + '<td>' + val.s_phone + '</td>' + '</tr>';
    }
    display += '</table>';
    return display;
}