billy8046
billy8046

I am trying to filter the output of a database query based on other fields in the table. From this, a person would pick their district:

$this->districtList = DB::lists('districts');

Then here, I want to use their district to display all the schools in the district:

$this->schoolList = DB::where('districts', '=', 'some district');

This is great except it gives me a collection with all the information of that record for each school. Can someone help me find the right method, or a way to trim down the output so I only get the school names? I am very new to working with databases and I really appreciate any help.

Last updated

raw99
raw99

$this->schoolList = DB::where('districts', '=', 'some district')->get();

foreach ($this->schoolList as $school) {

echo $school->name, '<br/>';

}

Last updated

billy8046
billy8046

Thanks for your response. I attempted to do it as you suggested, but I couldn't get it right. I still have a lot to learn. I eventually found a way to get the output I need by using this: $this->schoolList = DB::where('districts', '=', 'some district')->lists('school_name');

Seems to work for now.

raw99
raw99

billy8046 said:

Thanks for your response. I attempted to do it as you suggested, but I couldn't get it right. I still have a lot to learn. I eventually found a way to get the output I need by using this: $this->schoolList = DB::where('districts', '=', 'some district')->lists('school_name');

Seems to work for now.

That's not bad way too, even better... You're learning fast! :)

billy8046
billy8046

Thanks! :-) Finally figured out why my implementation of your suggestion didn't work...syntax error on my part. I've been staring at the same problems too long.

Works great though, so thanks again!

1-5 of 5