Ivan
Ivan

Reputation: 93

How to shuffle database value and display only 4

I have tried this but not working.

 $getPerson = mysqli_query($con,"SELECT * FROM Persons LIMIT 0,15");
 shuffle($getPerson)//how to set limit for this?

Upvotes: 1

Views: 70

Answers (1)

kamal pal
kamal pal

Reputation: 4207

You can use ORDER BY RAND() with LIMIT 0,4

SELECT * FROM Persons ORDER BY rand() LIMIT 0,4

Upvotes: 1

Related Questions