0

I have been getting value array and convert implode value comma separate ?

Model:

$result = $db2->query('SELECT tests FROM dpr_save_labtest where appointment_id = "8618204"');
            $data = $result->result_array();
            $res = implode(',', $data); 
            return $data;

Controller:

public function investigation_print_data()
    {
        $data = $this->doctor_health_model->investigation_print_data();
        echo json_encode($data);
        

    }

Array value:

Array
(
    [0] => Array
        (
            [tests] => COMPLETE HAEMOGRAM
        )

    [1] => Array
        (
            [tests] => CRP QUANTITATIVE
        )

)

View json print value:

'+res2[0]['tests']+'

Result:

RHEUMATOID FACTOR

I need this value:

RHEUMATOID FACTOR,CREATININE
0

1 Answer 1

1

When there is only one field in the SELECT, an implode does nothing. You need to collect the data and then return the imploded data.

$result = $db2->query('SELECT tests FROM dpr_save_labtest where appointment_id = "8618204"');
$tests = [];
while($data = $result->result_array()) {
    $tests[] = $data['tests'];
}
return implode(',', $tests);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.