Friends, I sincerely ask for help. This question has been tormenting for several months already, I am faced with the need to solve it in various projects. So that's the point.
There is a table in the database. for example cards.
There are many fields in the table, one of them is group
There are 15 entries in the cards table, 10 of which have the value group, for example 1
What do you need:
1) Since the records are scattered in a chaotic order, first of all you need to sort by group, so that all the cards that have group 1 are in order in the array one by one.
2) As soon as we meet the first of 10 cards that have the same group (1), we display it on the screen, and then we hide the other 9 cards under the spoiler. and so on with all. If a group is assigned to the card, in which there are no more cards, then we simply output it, if we meet a group of cards, we display the first one, the rest are hidden under the spoiler.
I thought a lot and I still don’t understand whether it can be done in one cycle, or do I need to think something different?
Here is the code:
$result = mysql_query("SELECT * FROM cards ORDER BY group"); while($card = mysql_fetch_array($result)) { //далее не знаю как можно это реализовать но более наглядно покажу что хочу echo $card['name']."<br/>"; //вывели к примеру карту, у которой группа 0 //Встретили карту с группой 1 (следующие 3 карты в массиве также имеют группу 1, поэтому выводим первую попавшею, а далее вставляем все остальные которые найдем с этой же группы под спойлер. //Вот, к примеру, код спойлера: <div class="spoiler-wrapper"> <div class="spoiler folded"><a href="javascript:void(0);">Название первой карты из группы</a></div><div class="spoiler-text">Все остальные карты из группы</div></div> }