wazzaday — 2011-03-26T17:08:40-04:00 — #1
i have an mySQL database with event information in it.
Date, Location, Type
there are 10 events in the database.
how would i get 5 of those events from random, and then with those 5 order by date.
i know how to get 5 random events, but i dont know how to then order the 5 i have.
r937 — 2011-03-26T17:27:57-04:00 — #2
use your query to retrieve the 5 random rows, then sort the array in php
(re)sorting 5 rows in php memory would be near instantaneous
centered_effect — 2011-03-26T18:01:31-04:00 — #3
You can use SQL to order it by how the user wants:
SELECT event FROM events ORDER BY date
SELECT event FROM events ORDER BY location
SELECT event FROM events ORDER BY type
r937 — 2011-03-26T18:04:06-04:00 — #4
see, wazzaday, this is what happens when you create multiple threads
centeredeffect obviously did not see your other thread where i suggested you sort the 5 rows in php
i've asked the moderators to merge your threads
spacephoenix — 2011-03-26T20:58:05-04:00 — #5
wazzaday, have a read of this thread (http://www.sitepoint.com/forums/mysql-182/speedy-order-rand-operation-727493.html), a number of ways of grabbing x number of records at random from a database are discussed and compared. It's probably a mute point if your only going to have 10 records but if the number of records is eventually going to be large, it's something worth considering.