outputting results in a random order with MySQL and PHP

Posted on 2007-10-09
Last Modified: 2008-01-09
Hi experts,

I have a form which gives the user an options as to how to display the results: the latest entry, most highly rated, and randomly.  With the fields I have, the first two can be done with a simple ORDER BY command in the sql, but outputting the results in a random order is a little more complex... I'm assuming that there isn't an SQL statement which will do this, so any idea on some PHP which might build the results randomly, e.g. into an array?

Question by:RowdyBurns
    1 Comment
    LVL 3

    Accepted Solution

    Well if you put your results into an array you can use the "shuffle()" api to mix up the array and then output the values...

    See more in the api manual:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now