MySQL select random records with limit

Started by teasebanksy, 03-27-2019

404
0
MySQL select random records with limit
  03-27-2019, 03:24 AM
#1
I have a query for selecting random records with a limit of 6.


$query = $this->pdo->prepare("SELECT * FROM " . $this->table . " ORDER BY rand() LIMIT " . $limit);

If I set the limit to 6, it will sometimes only show 4 records, sometimes 5.

How can I make it always show 6?

I have more than 6 records in the database.


I looked at some questions around this here but couldn't find a clear answer.

« Next Oldest | Next Newest »


Possibly Related Threads…
Thread Author Replies Views Last Post
Crud Operation using PHP mysql stevenporter 4 577 06-27-2020, 03:20 PM
Last Post: ydneatko
php mysql dkrao19 4 554 03-19-2019, 10:45 PM
Last Post: LordzSpectron
Wp auto post for random data. raresfranky 4 655 03-19-2019, 03:41 AM
Last Post: LordzSpectron



1 Guest(s)