I have 2 tables. 1 named tasks that has the rows [id, event_id, title] and the other table is named task_items with the rows [id, task_id, description, ...].
I am trying to run a query to retrieve all tasks with an event_id of x, then all task_items that match the id of any result from the previous query. I currently have 2 standalone queries, but don't know how to join them to work in-tandem. The current code that I have show all task_items associated with the event, but they aren't corresponding with each task. Task 0 in my database has 0 task_items, but my code is displaying the task_items for task 0 under task 1.
This is my query code:
$tasks = DB::table('tasks')->where('event_id', $request->route('id'))->get(); foreach($tasks as $task) { $taskItemID[] = $task->id; } $taskItems = DB::table('task_items')->whereIn('task_id', $taskItemID)->get(); This is my foreach loop:
@foreach($tasks as $task) <div><b>Task # :</b> </div> <div style="float:right;">mark as completed</div> </div> <div class="row" style="border: 1px solid #efefef;padding: 20px;"> @foreach($taskItems as $taskItem) <li></li> @endforeach @endforeach https://stackoverflow.com/questions/65623190/getting-the-results-of-a-query-depending-on-results-of-first-query January 08, 2021 at 11:47AM
没有评论:
发表评论