Order by rand() Reduce time II


/ Published in: PHP
Save to your folder(s)

Another version for my old Order by Rand function now it includes some PHP


Copy this code and paste it in your HTML
  1. //This is pseudo code for fetching 1 random row. I will update to add a new solution to fetch more random rows.
  2. function randomRow(table, Idcolumn) {
  3. maxRow = query("SELECT MAX(Idcolumn) AS maxID FROM table");
  4. if (maxRow.recordCount > 0) {
  5. do {
  6. randomID = randRange(1, maxRow.maxID);
  7. randomRow = query("SELECT * FROM table WHERE column = randomID");
  8. } while (randomRow.recordCount == 0);
  9. return randomRow;
  10. } else {
  11. return false;
  12. }
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.