Answer the question
In order to leave comments, you need to log in
Sample from the database
Hello! I have a db table like this:
CREATE TABLE `dialogs` (
`id` int(255) AUTO_INCREMENT,
`to` int(255),
`from` int(255),
`message` text,
`date` varchar(255),
`read` int(1) default '0',
PRIMARY KEY (`id`)
)
+----+------+------+-----------+------------+------+
| id | to | from | message | date | read |
+----+------+------+-----------+------------+------+
| 1 | 1 | 2 | Hello =) | 1379616725 | 0 |
| 2 | 2 | 1 | World. | 1379616743 | 1 |
| 3 | 1 | 2 | Push me)) | 1379616749 | 0 |
| 4 | 2 | 1 | World. | 1379616743 | 1 |
| 5 | 5 | 6 | World. | 1379616743 | 1 |
| 6 | 1 | 5 | World. | 1379616743 | 1 |
+----+------+------+-----------+------------+------+
`to`='2'
. The catch is that the from field must be unique (i.e. I don't need to get all the correspondence between 1 and 2 users, but 1 of their messages is enough). +----+------+------+-----------+------------+------+
| id | to | from | message | date | read |
+----+------+------+-----------+------------+------+
| 1 | 1 | 2 | Hello =) | 1379616725 | 0 |
| 6 | 1 | 5 | World. | 1379616743 | 1 |
+----+------+------+-----------+------------+------+
`to`='1'
+----+------+------+-----------+------------+------+
| id | to | from | message | date | read |
+----+------+------+-----------+------------+------+
| 2 | 2 | 1 | World. | 1379616743 | 1 |
+----+------+------+-----------+------------+------+
`to`='2'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question