This may sound stupid but I have problems to pull all records(messages) from just 1 ID. The messages are stored in a table berichten
CREATE TABLE IF NOT EXISTS `berichten` (
`bericht_id` int(11) NOT NULL AUTO_INCREMENT,
`gebruiker_id` smallint(4) NOT NULL DEFAULT '0',
`admin_id` smallint(3) NOT NULL DEFAULT '0',
`bericht` text,
`verzonden` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`isNieuw` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`bericht_id`),
KEY `gebruiker_id` (`gebruiker_id`),
KEY `admin_id` (`admin_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
In the admin section I have a page berichten(messages) which is refreshing every 10 seconds. On this page I first run a query to see if there are any new messages.
SELECT *
FROM berichten
WHERE isNieuw = 1;
If there is a new message, the entire message history from that particular user (gebruiker_id) should be forwarded to an available admin
SELECT gebruiker_id,
bericht,
verzonden
FROM berichten
and here I lost it. I can’t use gebruiker_id in a WHERE clause since it can be any gebruiker. I tried
SELECT DISTINCT gebruiker_id
and
ORDER BY gebruiker_id LIMIT 0,1
But I still get all messages. Maybe I am looking at this to long.