View Full Version : Mysql select rows that hasnt been selected

11-11-2011, 10:32 AM
Hi . I am building a live chat using mysql and the database is updated because of users entries . So the number ow rows in the table changes constantly . And need to use a query which will select the rows that hasnt been selected.
SO how do I do that ?

Thank you in advance!!!

Old Pedant
11-11-2011, 07:45 PM

Put an auto_increment field in the table. Say it is named chatNumber

When you send the current messages out to a user, make sure the chatNumber values are included.

In the client-side JavaScript code, just remember the highest chatNumber from already received messages and when you ake the AJAX call back for more messages (I *assume* you are using JS and AJAX??? you don't say, but it's probably the only likely choice), just send back that highest chatNumber.

That is, your AJAX URL might be something like moreMessages.php?last=731

So in the PHP code, you just do

$sql = "SELECT * FROM chatMessages WHERE chatNumber > " . $_GET["last"];

What could be simpler?