Now, I want to display 5 jobs within the Admin Category, but I want them pulled randomly from the database. ORDER BY RAND won't work because there are only 4 records. I need to display 5 records as it doesn't matter if the same record is displayed more than once. How do I do this?
I'd probably just loop through the result set as usual, but keep a counter of records displayed. Then if the counter is less than 5, reset the result pointer back to the first record, and start cycling through it again until the counter reaches 5. (Of course, check for 0 results first, so you don't get into an infinite loop.)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks