List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 8 2003 8:32pm
Subject:Re: Random Selects
View as plain text  
At 12:33 -0600 3/8/03, Darren Young wrote:
>I have a table called testimonials:
>
>+----------+-------------+------+-----+---------+----------------+
>| Field    | Type        | Null | Key | Default | Extra          |
>+----------+-------------+------+-----+---------+----------------+
>| id       | tinyint(3)  |      | PRI | NULL    | auto_increment |
>| can_use  | tinyint(1)  |      |     | 0       |                |
>| name     | varchar(64) |      |     | 0       |                |
>| location | varchar(64) |      |     | 0       |                |
>| quote    | text        |      |     |         |                |
>+----------+-------------+------+-----+---------+----------------+
>
>That contains 20 or so "customer testimonial" comments. I want to
>randomly display 3-4 of them every time a page loads (using PHP). Is
>there some type of random selction available within MySQL, as in:
>
>    SELECT RANDOM(id),name,location,quote FROM testimonials WHERE
>can_use=1 LIMIT 3;
>
>Or something to that effect or am I better served finding some way in
>PHP to do this?


.... ORDER BY RAND() LIMIT 3

ought to do it, unless your version of MySQL is older than 3.23.2.

>
>Thanks.

Thread
Random SelectsDarren Young8 Mar
  • Re: Random SelectsPaul DuBois8 Mar
    • RE: Random SelectsDarren Young8 Mar
      • RE: Random SelectsPaul DuBois8 Mar