I am making a website for college administration where professors log in and assign marks to the students they are teaching.

There's a table, called ***"IA\_Marks"*** in my database:

```
|Student_ID|Subject_Code|Name|Marks1|Marks2|Marks3|Semester|Division|

```

There's also a table called ***"Classroom\_Mapper"*** in my database, that helps map a professor to a classroom, with a subject:

```
|Prof_ID|Subject_Code|Semester|Division|

```

---

My Problem: 

I wish to fetch the `Subject_Code`, `Semester`,`Division` fields from the ***Classroom\_Mapper*** table so that I can use it to fetch the `Student_ID`,`Name`,`Marks1,2,3` from the ***IA\_Marks*** table.

To fetch the 3 fields from the ***Classroom\_Mapper*** table I will need the `Prof_ID` field, which is **unique** for every professor. 

Every professor logs in using his `Prof_ID`.

1. How do I fetch the Prof\_ID?
2. When I fetch the Prof\_ID, how do I fetch the other 3 fields from ***Classroom\_Mapper*** into my controller?

I need get those fields so that I can narrow down the `select` query results on ***IA\_Marks***, which currently displays the whole table. 

This is my current code: It shows the complete table, instead of just showing the records that are needed:

UserDefinedController.php

```
public function show(){        
        $data = DB::table('iamarks')->get();
        return view('ia',compact('data'));
 }

```

ia.blade.php

```
<table>
        <tr>
                <th>ID</th>
                <th>SUBCODE</th>
                <th>NAME</th>
                <th>IA1</th>
                <th>IA2</th>
                <th>IA3</th>
                <th>SEMESTER</th>
                <th>DIVISION</th>
        </tr>
        @foreach($data as $row)
            <tr>
                <td>{{ $row->ID}}</td>
                <td>{{ $row->subcode }}</td>
                <td>{{ $row->name }}</td>
                <td>{{ $row->IA1 }}</td>
                <td>{{ $row->IA2 }}</td>
                <td>{{ $row->IA3 }}</td>
                <td>{{ $row->semester }}</td>
                <td>{{ $row->division }}</td>
            </tr>
        @endforeach

    </table>

```

---

My idea of solving this problem:
(The syntax is definitely off! But I hope you can see where I'm heading with this.)

```
//Think of this as a pseudo-code
public function show(){
    $Prof_ID = LoggedInUser->Prof_ID;
    $Semester = DB::table('classroom_mapper')->pluck('Semester')->where('Prof_ID','=',$Prof_ID);
    $Division = DB::table('classroom_mapper')->pluck('Division')->where('Prof_ID','=',$Prof_ID);
    $data = DB::table('iamarks')->get()->where('Semester = $Semester' AND 'Division = $Division');
    return view('ia',compact('data'));
}

```

I just can't figure out how to fetch those values!