Is there a way to create a group where a row match? Hard to explain but ill try.
If I have a database with these fields:
ID: Name: GROUP_ID:
1 Jacob 1
2 Jonathan 1
3 Jesper 2
4 Jeod 2
5 Jeod 3
and I have a function that retrieves all of this data using PDOStatement::fetchAll
$users = $page->retrieve_users();
and then I want each GROUP_ID to be in a grouped div.
Now this displays all the names
foreach($users as $user){
echo "<div>".$user["name"]."</div>";
}
How do I configure it so each user["name"] that has the same GROUP_ID is in a own div?
I know I have to create a new array for each different GROUP_ID but I dont even know how to do that since I want it to be flexible meaning if I add a new user with a unique GROUP_ID it will be sorted to its own.
Can anyone help me with this?
Thanks in advance!
GROUP_IDand close / open yourdivwhen it changes. Assuming that the results are ordered byGROUP_ID...