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.
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
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
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
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.