简体   繁体   中英

Combine data from two mysql tables in HTML table Laravel 5.4

Trying to make one html table where is showing what login users choose. One login auth users and one form data. Here data is showing on page but scramled in table. Homedata is showing twice. Here is my index page where im trying to do:

 <table class="table" id="users-info">
                      <thead>
                        <tr>
                          <th scope="col">#</th>
                          <th scope="col">First Name</th>
                          <th scope="col">Last Name</th>
                          <th scope="col">Naional Number</th>
                          <th scope="col">Device</th>
                          <th scope="col">Reimbursment</th>
                          <th scope="col">Warranty</th>
                        </tr>
                      </thead>
                      <tbody>
                     @if(count($users) > 0)
                                @foreach($users as $user)

                                    <tr>
                                      <th scope="row">{{ $user->id }}</th>
                                      <td>{{ $user->firstname }}</td>
                                      <td>{{ $user->lastname }}</td>
                                      <td>{{ $user->phone }}

                                    @foreach($homedata as $homedatas)

                                          <td>{{$homedatas->device}}</td>
                                          <td>{{$homedatas->reimburse_Pension}}</td>
                                          <td>{{$homedatas->bonus_remainder}}</td>          
                                    @endforeach
                                    </td>
                                    </tr>
                                @endforeach     
                            @endif  
                      </tbody>
                </table>

Please help. if there is another way please feel free suggest.

Hey everyone who share the same problem. I add in second foreach ->slice(0, 1) and that foreach just going once, that automaticaly means no duplicate data :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM