shuffle random MYSQL results

前端 未结 4 443
广开言路
广开言路 2020-12-11 05:27

The following code displays random database images as well as one specific image (which is what I want). How can I shuffle these results after database query as image ID 11

4条回答
  •  不思量自难忘°
    2020-12-11 06:08

    You can shuffle them after they are retrieved to php.

    $photos = array();
    while ($get_photo = mysql_fetch_array($photo))
        $photos[] = $get_photo;
    
    shuffle($photos);
    

    Or you can do it with subqueries:

    SELECT A.* FROM (
        SELECT * FROM `profile_images` 
        ORDER BY (ID = 11) DESC, RAND()      
        LIMIT 7
    ) as A
    ORDER BY RAND()
    

提交回复
热议问题