Hi guys (and girls),
I've been thinking a bit about how to handle result sets when you join tables in one-to-many relationships.
Let's say we have a users-table, and a messages-table. The users-table has a one-to-many relationship with the messages-table. When you join them, you get something like this as a result:
+--------+----------+-----------+---------+
| UserID | UserName | MessageID | Message |
+--------+----------+-----------+---------+
| 1 | Bob | 1 | Hi! |
| 1 | Bob | 2 | Hello! |
| 1 | Bob | 3 | Wow! |
| 2 | David | 4 | Hey! |
| 2 | David | 5 | Hey you |
+--------+----------+-----------+---------+
Now, if I want to display this, and only show the username one time, what is the best way of doing this? Should I store the user id in a temp variable, and check in the loop if it has changed, or is there a more convenient way of doing this?