Skip foreach result every two results

Asked

Viewed 49 times

-1

I have some results in the bank and need to align them according to the image below. But I could not. I am doing in Laravel 5.8. inserir a descrição da imagem aqui

<table style="border-collapse: collapse; width: 100%;" border="0">
      <tbody>
        @foreach ($equipe as $key => $a)
        <tr>
          <td style="width: 50%;">
            <p style="text-align: center;"><strong>{{$a->admin->name}}</strong></p>
            <p style="text-align: center;">Controladora Municipal</p>
          </td>
          <td style="width: 50%;">
            <p style="text-align: center;"><strong>{{$a->admin->name}}</strong></p>
            <p style="text-align: center;">Controladora Municipal</p>
          </td>
        </tr>   
        @endforeach
      </tbody>
    </table>

It’s as if every 2 foreach results I could fit into the table. How can I align the foreach result so?

  • It seems to be confusing front-end and back-end, if back-end data is coming as expected, alignment is style.

  • i need to play this image result.. know how to do it? I tried using a break, etc...

  • Break? I believe I have to edit the question and add the CSS tags, Flex-Grid, Flex-box... Put the result you have...

  • wanted to know how I would do it in html so...

  • So you actually need to analyze the structure. What you want sounds more like a list <ul> than with table... What exactly do you want is a table? Have other fields? Because there are 2 rows and 2 columns of the same type of data. Something doesn’t feel right)

  • Likely you have bootstrap in the project if you have take a look at grids. Already facilitating your life, you will probably have to use 6 columns, getting something like: col-sm-6 in the classes.

Show 1 more comment

1 answer

0

Hi, João. What’s up? It seems to me that your doubt is more related to html/css than to php/Standard.

Anyway, for your question, imagining that you expect to receive the values always in the same position, due to the job description being written in a static way , as shown in this line

<p style="text-align: center;">Controladora Municipal</p>

One can easily access the position of the array elements and insert directly into their html. It would look something like:

<table style="border-collapse: collapse; width: 100%;" border="0">
  <tbody>
    <tr>
      <td style="width: 50%;">
        <p style="text-align: center;"><strong>{{$equipe[0]->admin->name}}</strong></p>
        <p style="text-align: center;">Controladora Municipal</p>
      </td>
      <td style="width: 50%;">
        <p style="text-align: center;"><strong>{{$equipe[1]->admin->name}}</strong></p>
        <p style="text-align: center;">Controladora Municipal</p>
      </td>
    </tr>     
  </tbody>
</table>

Of course, this is just another way to access that information, and in that case, you wouldn’t need the foreach.

Another observation I would make was to not use a table for this type of data. This information could be easily structured with one of the options:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.