PHP: How to display multiple MySQL table records per HTML table row using MySQLi

后端 未结 2 1620
闹比i
闹比i 2021-01-24 19:00

I would like to display a group of elements in a row in php from mysql database. I already did it, but my data appears in one long column. I would like every new element to appe

2条回答
  •  梦谈多话
    2021-01-24 19:34

    There are few issues with your code, such as:

    • You're creating a new table in each iteration of while() loop.
    • You're using the same div ids, element1 and content1 for all of your table rows. Use class instead. However, based on your question,

      I would like every new element to appear one next to the other.

      You can use the id attributes there, but you have to take the entire

      ...
      and
      ...
      out of the while() loop. And of course, change id="hovers" to class="hovers" and the associated CSS accordingly.

    So the solution code would be like this:

    <?= $product['title']; ?>


    Update(1):

    From OP's comment,

    I am trying to have 3 interviews in a row and several rows with interviews.

    The solution would be to have three table cells in each row,

    '; } ++$counter; ?>
    <?= $product['title']; ?>


提交回复
热议问题