Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2010
    Location
    Armenia
    Posts
    41
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Mysql select rows that hasnt been selected

    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!!!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,574
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    Easy.

    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
    Code:
    $sql = "SELECT * FROM chatMessages WHERE chatNumber > " . $_GET["last"];
    ...
    What could be simpler?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •