0

First I want to pick all the specific users. I think this is done like this?

$res= mysqli_query($con, "SELECT * FROM users WHERE test='$value'");
$num = mysqli_num_rows($res);

echo $num;

Lets say there are 37 users who achieves the requirements in the SELECT($num=37). How do I pick 7 random users of those 37 who I then UPDATE?

Rizier123
  • 58,877
  • 16
  • 101
  • 156
anon
  • 237
  • 2
  • 11

2 Answers2

3
SELECT * FROM users 
WHERE test='$value'
ORDER BY rand()
LIMIT 7
juergen d
  • 201,996
  • 37
  • 293
  • 362
2

You could use append

Order by rand() limit 7

To the query Or get all results and use array shuffle

The first way is easier to implement the second will perform faster for larger datasets

exussum
  • 18,275
  • 8
  • 32
  • 65