用户列表有限制

I have a list in which registered users and 5 show a button below that says var more users. By giving the button shows you another 5 more users.

my query:

SELECT * FROM users ORDER BY id DESC LIMIT 0, 5

where zero is adding 5 each time that is given to pin see more.

The problem is that if someone registers while another looks at the list, a user shows repeated.

Example: if I have 10 users that are displayed in descending should show,

10, 9, 8, 7, 6, 5, 4, 3, 2, 1

If at the time the user sees these registers and other records after this button gives the user see more, doubling the record 6. Were

10, 9, 8, 7, 6, 6, 5, 4, 3, 2, 1

Is there any way to fix this?

try using SELECT DISTINCT to get just the individual names

SELECT DISTINCT * FROM users ORDER BY id DESC LIMIT 0, 5

I don't think that there is a "correct" way of doing this. This page has some great tips, though: https://coderwall.com/p/lkcaag

Yes, you don't use the same query again, but you use the id of the last record fetched as starting point from there on.

WHERE id < $lastid ORDER BY id DESC LIMIT 0, 5

The order needs to be the same though

If you are not using ajax, you can have something like

<?php

  if(!isset($_GET['num']))
      $num = 5;
  else
      $num = $_GET['num'];

  $res = mysql_query("SELECT * FROM users ORDER BY id DESC LIMIT 0, '".$num."' ");

  while($arr = mysql_fetch_array($res))
  {
    //display data
  }
?>

then have the show more button like

<a href="samepage.php?num=<?php echo $num+5;?>">
  <button id="show_more">show more</button>
</a>

You can make it a whole lot fancier using ajax