0

I have a TABLE A called diagnoses . It has a disease_id and a visit_id. I am trying to return the diagnosis from TABLE A along with the disease name and visit details. I keep getting sql syntax errors. Is there a recommended way to push an objects to the array?

My code is

public function diagnosis_diseases(Disease $disease) {

        $id = $disease->id;

        $items = DB::select(DB::raw('SELECT * FROM diseases WHERE diseases.id = '.$id.'  ;'));
        foreach($items as $item){
            $diagnosis = DB::select(DB::raw(' select * from diagnoses
                   where disease_id = '. $id.';' ));

            $items->push($diagnosis);
        }

        dd($items);

    } 

1 Answer 1

1

You might need to use an inner join:

public function diagnosis_diseases(Disease $disease) {

        $id = $disease->id;

        $items = DB::select(DB::raw('SELECT * FROM diseases WHERE diseases.id = '.$id.'  ;'));
        foreach($items as $item){
            $diagnosis = DB::select(DB::raw(' select * from diagnoses
                   inner join diseases on diagnoses.id = ' .$id' '));

            $items->push($diagnosis);
        }

        dd($items);
    } 
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.