I am building a basic SMS to web gateway where one person on my web site will be able to chat via SMS with multiple phone users.
My table of messages is setup as such:
id | message | smsFrom | smsTo |time
For simplification some sample data would something like:
smsFrom | smsTo
4 | 5
3 | 5
5 | 4
3 | 5
5 | 3
7 | 5
9 | 5
8 | 5
Where 5
represent a chat operator and the other numbers represent people talking vis SMS to them.
What is the best way, either via SQL
or PHP
group my data by operator AND number so that I can then display my conversations in different tabs or however I decide to display them.
My expected output would be something like:
4 | 5
5 | 4
3 | 5
3 | 5
5 | 3
7 | 5
9 | 5
8 | 5
I want to select all of the rows where the to
or from
fields match my operators number, then group all of those results by the numbers that are not my operators number to create conversations which I can then format as I please.