Hi everyone, I'm new here and I need some help. My English is not that good, so I hope my sentences are understandable. I would like to read out two tables. The first table should be output completely and the second table only the matching entries. My code looks like this:
$dbkompetenzen = DB::table('LD_Kompetenzen') ->leftjoin('LD_SHD', 'LD_SHD.KompetenzID', '=', 'LD_Kompetenzen.id') ->where('LD_Kompetenzen.FachID','=',$idfach) ->where('LD_Kompetenzen.ThemenID','=',$idthemen) ->where('LD_SHD.SHDID','=',$shdid) ->select('LD_Kompetenzen.id', 'LD_Kompetenzen.FachID', 'LD_Kompetenzen.ThemenID', 'LD_Kompetenzen.Kompetenz', 'LD_SHD.SHDID', 'LD_SHD.Ergebnis', 'LD_SHD.Stufe', 'LD_SHD.Niveau', 'LD_SHD.Note', 'LD_SHD.Datum', 'LD_SHD.Kuerzel', 'LD_SHD.background') ->get();
Unfortunately I only get 2 rows from the table LD_SHD (there is nothing more). The LD_Kompetenzen table contains 14 rows. I would like to output all 14 lines, if a user (SHDID) has matching entries for the ID "Kompetenzen", then all 14 values should still be output. If there are no SHDID entries, all 14 lines of "Kompetenzen" should be output and the SHDID entries should display "null". I hope my concern is understandable.
Can you please try with below.
$dbkompetenzen = DB::table('LD_Kompetenzen') ->leftjoin('LD_SHD','LD_Kompetenzen.id','=', 'LD_SHD.KompetenzID') ->where('LD_Kompetenzen.FachID','=',$idfach) ->where('LD_Kompetenzen.ThemenID','=',$idthemen) ->where('LD_SHD.SHDID','=',$shdid) ->select('LD_Kompetenzen.id', 'LD_Kompetenzen.FachID', 'LD_Kompetenzen.ThemenID', 'LD_Kompetenzen.Kompetenz', 'LD_SHD.SHDID', 'LD_SHD.Ergebnis', 'LD_SHD.Stufe', 'LD_SHD.Niveau', 'LD_SHD.Note', 'LD_SHD.Datum', 'LD_SHD.Kuerzel', 'LD_SHD.background') ->get();
I discovered the Join ON function. This makes my project work!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community