Если я выполню это, я получу первую строку arrayarrayarray (…), но вторая пуста. Есть ли способ выполнить это дважды?
РЕДАКТИРОВАТЬ: У меня была опечатка в этом посте, оригинальный вопрос стоит
Решение
$rows является подготовленным объектом заявления. Этот объект реализовать Traversable так что вы можете использовать foreach получать результаты, а не напрямую вызывать метод выборки. Но после того, как вы получили результаты один раз, вы не можете получить их снова. Вам нужно будет выполнить запрос снова или сохранить результаты в массиве во время первой итерации и использовать сохраненные результаты во второй раз, например так:
Кроме того, я не уверен, как echo($row) работает здесь, так как я бы предположил, $row будет массив, но это не относится к делу.
Другие решения
Я чувствую, что это проблема с печатанием и должна быть:
following on from this question now i need to style the output only to find that php does not like my way of putting tags I also tried to encapsulate it in » and the . or but still did not work.
It does not work, shows no result. 🙁 Pulling hairs out! Looked at alternative questions but northing clear enough.
I have a pretty standard database like:
and I want to display it in a table, but every row in the DB needs to be a column in HTML table:
I get all the data in one long column. How do I break the column after every SQL row?
Note: $data is an array of objects that contain properties with the field values (you can probably figure that out from the example).
EDIT:
I found the solution, see my answer, it’s simple and elegant.

6 Answers 6
I figured it out, turns out it’s a pretty simple solution with few cycles and pre-populating an array before writing rows and cells.
I tested it, works like a charm. 😉 It might be useful for someone, so here it is:
Answer has been updated for adjusted original post requirements as follows:
this is a wierd (or elegant) way to get what you want done and it will likely take tweaking to get it to look pretty, but it seems to work as you can see at the following url
it has the php div method on top and does indeed show that the div’s are different sizes as you had hoped would not happen. I have however come up with elegant/ugly solution that works with a table.
i have to admit it is strange, but it keeps your tables with the correct heights .. the next more complicated part would be to set how many columns to show as this method makes it much more complicated to break after 5 columns like the div method I had earlier.