How display random articles?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
15 views
Hello.

Want the articles page to display other random articles made in the following way:

$randomId = []; $res = $dbh->query("SELECT * FROM goods WHERE id"); foreach ($res as $key) { $randomId[] = $key["id"]; }


ID all articles brought into the array and brought by random.

How this approach is correct and how much will be shipping database?

p.s. iDisk I have 150 (not alternately)
by | 15 views

2 Answers

0 like 0 dislike
1 request!
$res = $dbh->query("SELECT * FROM goods ORDER BY RAND() LIMIT 10");

2. Option 2 (faster with large number of records): https://stackoverflow.com/a/4329447
by
0 like 0 dislike
SELECT * FROM `goods` ORDER BY RAND() LIMIT 10

You have more than 500 requests per second to database? What kind of load it:?
by

Related questions

0 like 0 dislike
6 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 11, 2019 by troodi
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users