+ 1

How do I retrieve post randomly from my database

Blog data base

4th Nov 2018, 8:20 PM
Precious Obaseki
Precious Obaseki - avatar
5 Antworten
0
What if I use ORDER BY RAND()
5th Nov 2018, 12:31 PM
Precious Obaseki
Precious Obaseki - avatar
+ 1
why would my answer be downvoted? that makes zero sense. it’s not an incorrect answer.
5th Nov 2018, 12:54 PM
Panayiotis Spanos
Panayiotis Spanos - avatar
+ 1
Precious Obaseki you said “retrieve” not order them randomly...
5th Nov 2018, 8:18 PM
Panayiotis Spanos
Panayiotis Spanos - avatar
0
without knowing more about the structure of your database, i would suggest that you add all the post id’s to an array, then get the length of that array, call a random number generator to give you a random number between 0 and length-1, get the id at that location in the array, and output the post with that ID from your database
5th Nov 2018, 2:59 AM
Panayiotis Spanos
Panayiotis Spanos - avatar
0
Maybe requesting a json from db and parse it into an object and get a random value
5th Nov 2018, 12:01 PM
Seniru
Seniru - avatar