ranking database record and display the record at random

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
paulng
Forum Commoner
Posts: 28
Joined: Mon Jul 11, 2005 9:31 am

ranking database record and display the record at random

Post by paulng »

Hi Everyone.

I'm try to retrieve data from a database, displaying record at random and rank them according to the value of a field in my database called DisplayOrder.

I Have a field called DisplayOrder, using the SQL statement below I can display the database record in display order

sql_query = "SELECT * FROM mod_en WHERE StartDate <= '$currdate' AND EndDate >= '$currdate' ORDER BY DisplayOrder ASC LIMIT 4";

I'm trying to display the data at random but keeping the display order. Using both the RAND and ORDER BY doesnt work. I dont know whether I need to write some separate PHP code to achieve this.

Can anyone help please.
Post Reply